记录一下,方便自己查看 代码片段:
//将附图上传服务器
@RequestMapping(value ="/uploadFigure", method = RequestMethod.POST)
@ResponseBody
public Result uploadFigure(@RequestParam("userId") String userId,
@RequestParam("photos") MultipartFile[] files){
try {
if(files.length<=0){
return Result.buildFailureWithMsg("没有文件");
}
//存放文件路径
String[] figure_path=new String[files.length];
for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i];
String fileName=file.getOriginalFilename();
//新的文件名前加上uuid,防止重名
String newFileName ="F:/home/jzw_data/pic/"+userId+"/"+"uuid"+fileName;
File newFile = new File(newFileName);
if(!newFile.exists()){
newFile.getParentFile().mkdirs();
}
file.transferTo(newFile);
figure_path[i]=newFileName;
}
return Result.buildSuccessWithData(figure_path);
}catch (Exception e){
e.printStackTrace();
return Result.buildFailureWithMsg("文件上传失败");
}
}
配置信息:
spring: servlet: multipart: #允许最大本次请求总文件大小 max-request-size: 100MB #允许最大单个文件大小 max-file-size: 10MB