Вы можете добиться переименования файла, как показано ниже. Для проверки перейдите на uploadDir, и у вас будет файл с "renameTest"
.
Вы можете добавить clientId + uploadTime
к имени файла, чтобы избежать тех же имен файлов в базе данных
@PostMapping(value = "/post")
public String renameMultipartFile(@RequestParam("file") MultipartFile file) {
String uploadDir = "yourPath";
String filename = "renameTest";
Path saveTO = Paths.get(uploadDir + filename);
try {
try {
Files.copy(file.getInputStream(), saveTO);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error : " + e.getMessage());
}
return "File uploaded successfully";
} catch (Exception e) {
e.printStackTrace();
return "Error : " + e.getMessage();
}
}