/**
* 文件上传
*
* @param uploadFile
* @return
*/
@ResponseBody
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public AjaxReturn uploadAttachFile(@RequestParam("feedbackfile") MultipartFile uploadFile) {
AjaxReturn result = Ajax.fail();
if (!uploadFile.isEmpty()) {
JSONObject fileJson = new JSONObject();
fileJson.put("fileRealName", uploadFile.getOriginalFilename());
String fileSuffix = FilenameUtils.getExtension(uploadFile.getOriginalFilename());
fileJson.put("fileSuffix", fileSuffix);
fileJson.put("fileSize", uploadFile.getSize());
fileJson.put("fileType", uploadFile.getContentType());
String fileStoreName = System.currentTimeMillis() + String.valueOf(RandomUtils.nextInt(10000, 99999)) + "." + fileSuffix;
fileJson.put("fileStoreName", fileStoreName);
fileJson.put("fileStorePath", uploadStorePath);
boolean isUploadOk = false;
try {
uploadFile.transferTo(new File(uploadStorePath + SystemUtils.FILE_SEPARATOR + fileStoreName));
isUploadOk = true;
} catch (IOException e) {
log.error("upload feekback file error:{}", e.toString());
}
result.setOk(isUploadOk).setData(fileJson);
}
return result;
}
0 回复
添加回复
请先登陆