@PostMapping(value = "/uploadFile")
public String uploadFile(@RequestParam(value = "md5") String md5,
@RequestParam(value = "file") MultipartFile file) {
String fileurl = fileService.uploadFile(md5,file);
return fileurl;
}
public String uploadFile(String md5, MultipartFile file) {
String fileName = file.getOriginalFilename();
String suffix = fileName.substring(fileName.length() - 3);
String filePath = "D:/upload";
if (!file.isEmpty()) {
if (!new File(filePath + "/" + suffix + "/").exists()) {
new File(filePath).mkdirs();
}
filePath = filePath + "/" + suffix + "/" + md5 + "." + suffix;
try {
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
} catch (IOException e) {
logger.error("文件上传失败", e);
throw new StoredProcedureException();
}
}
return filePath;
}
yml配置下
http:
multipart:
enabled: true
max-file-size: 50MB
max-request-size: 50MB