版权声明:开源共享,觉得文章对你有用就拿去吧,内容如果侵犯您的权益或者您有其他需要交流的,可以联系taishanglianqing#qq.com(把#替代为@即可) https://blog.csdn.net/qq_22585453/article/details/80390251
后台
@ApiOperation(notes = "返回一个文件名,需要调用 /home/download方法才可以获取到文件", httpMethod = "POST", value = "文件/图片上传")
@RequestMapping("/uploaderPic2")
@ResponseBody
public Object uploadHeadPic2(@RequestParam("file")MultipartFile file,HttpServletRequest request,HttpServletResponse response) throws IOException{
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String uploadFilename = Random.getId()+suffix;
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(Constant.UPLOAD_DIR, uploadFilename));
Map<String, String> map = new HashMap<String, String>();
map.put("data",picDownloadServerUrl+"?filename="+uploadFilename);//这里应该是项目路径
return map;//将图片地址返回
}
jsp
root.editor = new wangEditor('#product-content');
root.editor.customConfig.uploadImgServer = 'http://api.farmmermall.com/WebUploader/uploaderPic2'
root.editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
root.editor.customConfig.uploadImgMaxLength = 5;
root.editor.customConfig.uploadFileName = 'file';
root.editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) {
// 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)
// insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果
// 举例:假如上传图片成功后,服务器端返回的是 {url:'....'} 这种格式,即可这样插入图片:
var url =result.data;
insertImg(url);
// result 必须是一个 JSON 格式字符串!!!否则报错
}
}
root.editor.create();