use of cn.exrick.common.pojo.KindEditorResult in project xmall by Exrick.
the class ImageController method kindeditor.
@RequestMapping(value = "/kindeditor/imageUpload", method = RequestMethod.POST)
@ApiOperation(value = "KindEditor图片上传")
public KindEditorResult kindeditor(@RequestParam("imgFile") MultipartFile files, HttpServletRequest request) {
KindEditorResult kindEditorResult = new KindEditorResult();
// 文件保存路径
String filePath = request.getSession().getServletContext().getRealPath("/upload") + "\\" + QiniuUtil.renamePic(files.getOriginalFilename());
// 检查文件
String message = QiniuUtil.isValidImage(request, files);
if (!message.equals("valid")) {
kindEditorResult.setError(1);
kindEditorResult.setMessage(message);
return kindEditorResult;
}
// 转存文件
try {
// 保存至服务器
File file = new File((filePath));
files.transferTo(file);
// 上传七牛云服务器
String imagePath = QiniuUtil.qiniuUpload(filePath);
if (imagePath.contains("error")) {
kindEditorResult.setError(1);
kindEditorResult.setMessage("上传失败");
return kindEditorResult;
}
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
}
kindEditorResult.setError(0);
kindEditorResult.setUrl(imagePath);
return kindEditorResult;
} catch (IOException e) {
e.printStackTrace();
}
kindEditorResult.setError(1);
kindEditorResult.setMessage("上传失败");
return kindEditorResult;
}
Aggregations