Skip to content

Commit

Permalink
Merge pull request #382 from sam80180/main
Browse files Browse the repository at this point in the history
fix: be able to upload files w/o extension
  • Loading branch information
ZhouYixun authored Sep 19, 2023
2 parents 75fcfe3 + 6cf96e9 commit 3bad50e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public String upload(String folderName, MultipartFile file) throws IOException {
folder.mkdirs();
}
//防止文件重名
final String nombre = file.getOriginalFilename();
final int p = nombre.lastIndexOf(".");
File local = new File(folder.getPath() + File.separator +
UUID.randomUUID() + file.getOriginalFilename()
.substring(file.getOriginalFilename().lastIndexOf(".")));
UUID.randomUUID() + (p>=0 ? nombre.substring(p) : nombre));
try {
file.transferTo(local.getAbsoluteFile());
} catch (FileAlreadyExistsException e) {
Expand All @@ -81,9 +82,10 @@ public String uploadV2(String folderName, MultipartFile file) throws IOException
folder.mkdirs();
}
//防止文件重名
final String nombre = file.getOriginalFilename();
final int p = nombre.lastIndexOf(".");
File local = new File(folder.getPath() + File.separator +
UUID.randomUUID() + file.getOriginalFilename()
.substring(file.getOriginalFilename().lastIndexOf(".")));
UUID.randomUUID() + (p>=0 ? nombre.substring(p) : nombre));
try {
file.transferTo(local.getAbsoluteFile());
} catch (FileAlreadyExistsException e) {
Expand Down

0 comments on commit 3bad50e

Please sign in to comment.