public void uploadFile(@RequestParam(value = "file", required = false)MultipartFile[] file,HttpServletRequest request, HttpServletResponse response) throws IOException {
//附件上传
for (MultipartFile multipartFile : file) {
//获取文件名
String fileName = multipartFile.getOriginalFilename();
if(null!=fileName && !"".equals(fileName)){
try {
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();//文件扩展名
String newfilename = StringUtil.getUUID() + "." + fileExt; //生成uuid文件名
String savePath = "upload/images/" + newfilename;
File folder=new File(PropUtils.get("web.root")+"upload/images");
if(!folder.exists()){
folder.mkdirs();//如果文件夹不存在 创建文件夹
}
//上传文件
// multipartFile.transferTo(new File(PropUtils.get("web.root") + savePath));
//压缩文件
ImageHelper.compress(multipartFile.getInputStream(), new File(PropUtils.get("web.root") + savePath), 700);
//数据库保存图片路径信息
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
}public void uploadFile(@RequestParam(value = "f