1.图片上传

 var E = window.wangEditorvar editor = new E('#editorMenu','#editor')//开启debug模式editor.customConfig.debug = true;// 关闭粘贴内容中的样式editor.customConfig.pasteFilterStyle = false// 忽略粘贴内容中的图片editor.customConfig.pasteIgnoreImg = true// 使用 base64 保存图片//editor.customConfig.uploadImgShowBase64 = true// 上传图片到服务器editor.customConfig.uploadFileName = 'myFile'; //设置文件上传的参数名称editor.customConfig.uploadImgServer = 'upload'; //设置上传文件的服务器路径editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024; // 将图片大小限制为 3Meditor.customConfig.uploadImgMaxLength = 5;editor.customConfig.uploadImgHooks = {success: function (xhr, editor, result) {// 图片上传并返回结果,图片插入成功之后触发// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果},fail: function (xhr, editor, result) {// 图片上传并返回结果,但图片插入错误时触发// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果},error: function (xhr, editor) {// 图片上传出错时触发// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象}}

后台代码

@Data
public class WangEditor {private Integer errno; //错误代码,0 表示没有错误。private String[] data; //已上传的图片路径public WangEditor(String[] data) {super();this.errno = 0;this.data = data;}}
@RequestMapping(value = "/upload",method=RequestMethod.POST)@ResponseBodypublic WangEditor uploadFile(@RequestParam("myFile") MultipartFile multipartFile,HttpServletRequest request) {try {// 获取项目路径String realPath = request.getSession().getServletContext().getRealPath("");InputStream inputStream = multipartFile.getInputStream();String contextPath = request.getServletContext().getContextPath();// 服务器根目录的路径String path = realPath.replace(contextPath.substring(1),"");// 根目录下新建文件夹upload,存放上传图片String uploadPath = path + "upload";// 获取文件名称String filename = Calendar.getInstance().getTimeInMillis()+"image";// 将文件上传的服务器根目录下的upload文件夹File file = new File(uploadPath, filename);FileUtils.copyInputStreamToFile(inputStream, file);// 返回图片访问路径String url = request.getScheme() + "://" + request.getServerName()+ ":" + request.getServerPort() + "/upload/" + filename;String [] strs = {url}; WangEditor we = new WangEditor(strs);return we;} catch (IOException e) {logger.error("上传文件失败", e);}return null;}

2.多图片上传

editor.customConfig.customUploadImg = function (files, insert) {var data= new FormData();for(var i=0;i<files.length;i++){data.append("files",files[i]);}$.ajax({url:basePath + 'uploadFile/wangEditUploadImag',type: "POST",data: data,success:function(da){if(da.errno == 0){for(var j=0;j<da.data.length;j++){insert(da.data[j]);}}else{alert(da.msg);return;}}});
}   
@RequestMapping(value = "/upload1",method=RequestMethod.POST)@ResponseBodypublic WangEditor uploadFile(@RequestParam("files") MultipartFile[] files,HttpServletRequest request) {try {List list = new ArrayList();for(MultipartFile multipartFile:files) {// 获取项目路径String realPath = request.getSession().getServletContext().getRealPath("");InputStream inputStream = multipartFile.getInputStream();//String contextPath = request.getServletContext().getContextPath();//logger.info(contextPath);// 服务器根目录的路径String path = realPath;// 根目录下新建文件夹upload,存放上传图片String uploadPath = path + "upload";// 获取文件名称String filename = Calendar.getInstance().getTimeInMillis()+"image";// 将文件上传的服务器根目录下的upload文件夹File file = new File(uploadPath, filename);FileUtils.copyInputStreamToFile(inputStream, file);// 返回图片访问路径String url = request.getScheme() + "://" + request.getServerName()+ ":" + request.getServerPort() + "/upload/" + filename;list.add(url);}//ArrayList<String> list=new ArrayList<String>();String[] strings = new String[list.size()];list.toArray(strings);WangEditor we = new WangEditor(strings);return we;} catch (IOException e) {logger.error("上传文件失败", e);}return null;}

wangEditor图片上传相关推荐

  1. SSM开发书评网29:后台二:wangEditor图片上传;(主要内容是【wangEditor图片上传的文档要求】,【Spring MVC整合FileUpload组件,以实现文件上传功能】)

    说明: (1)本篇博客内容说明:[在后台系统,我们点击新增按钮后,会弹出新增图书对话框]→[该对话框中,包含一个wangEditor富文本编辑器]→[wangEditor富文本编辑器中,可以包含图片] ...

  2. 阿里云oss云存储图片上传在wangEditor富文本编辑器上的集成

    调用方式 html: <textarea name="newsinfo_content" id="editor" style="height:5 ...

  3. wangEditor - 轻量级web富文本编辑器(可带图片上传)

    业务需求: 通过后台编辑文章和图片,上传到前端界面,展示新闻消息模块.这个时候,需要一款简洁的编辑器,百度编辑器是最常用的一种,但是功能太过于复杂,而wangEditor - 轻量级web富文本编辑器 ...

  4. wangEditor Java富文本的图片上传

    上一篇 wangEditor的配置:https://blog.csdn.net/qq_35349982/article/details/103288508 这里主要讲 java后台 我这里用的是七牛云 ...

  5. wangeditor php上传本地图片,wangEditor 本地上传图片配置

    let editor; new Vue({ el: '#app', data() { return {} }, mounted() { this.initEditor(); }, methods: { ...

  6. 【富文本】wangeditor编辑器简单使用(自定义图片上传)

    一.wangeditor 官网 二.引入 // 安装 npm i wangeditor --save// 使用 import E from "wangeditor" const e ...

  7. vue中使用wangeditor富文本编辑器(含图片上传和回显)

    最近在写vue的项目中,遇到一个需求,点击编辑,显示弹框,在弹框中的富文本编辑器中编辑自定义文本样式,可以上传图片并回显.编辑完成确定后显示在页面上. 首先先写一个editor.vue的页面.(建议单 ...

  8. wangeditor php上传本地图片,配置wangEditor 实现图片上传

    首先新建editor.vue文件,用于写配置项 方法1:使用 base64 编码直接将图片插入到内容中 优点 :配置简单 this.editor.customConfig.uploadImgShowB ...

  9. 使用wangEditor批量上传并且保证图片顺序

    wangEditor文档 环境搭建 使用wangEditor SpringMVC 1.pom.xml <project xmlns="http://maven.apache.org/P ...

最新文章

  1. AI进军服装零售产业:微软小冰与特步推出定制化服装设计生产及零售平台
  2. information_schema.character_sets 学习
  3. NIPS不改名再引风波:签名抗议活动开启,大咖纷纷发声支持
  4. SPSS问卷或量表调查研究需要多少份或要求多大的样本量?【SPSS 062期】
  5. java 旅游网站项目实现_基于jsp的旅游网站a-JavaEE实现旅游网站a - java项目源码
  6. 瑞星云安全截获新感染病毒 6月感染网民263万
  7. Python数学建模 空间插值
  8. 「双拼输入法安利」清欢实践了四个月,真的好用!
  9. 5种Alexa世界排名作弊方式(转)
  10. 酷柚易汛进销存-如何新增付款单?
  11. 成功解决ValueError: Only TF native optimizers are supported in Eager mode
  12. 服务器如何释放虚拟内存,服务器如何释放虚拟内存
  13. php调用天气预报接口,PHP调用百度天气接口API实现查询实时天气
  14. 三维图形的平移,旋转与错切
  15. 文华财经期货量化短线策略支撑压力指标公式,短线行情无未来函数多空均线红涨绿跌信号
  16. jquery根据name获取对象
  17. 怎样成为一名优秀的程序员
  18. 格创东智当选深圳市工业互联网联盟首批理事单位
  19. R语言机器学习实战之多项式回归
  20. 研发人员考核与激励学习总结

热门文章

  1. esp8266WiFi模块通过MQTT连接华为云
  2. K8s关于异常Pod的处理
  3. 详谈parameterType与resultType的用法
  4. GitHub 优秀的开源项目学习
  5. Excel技能培训-INDIRECT实现拼接动态引用单元格,trl+pageDown速切换工作簿,多工作表求和,多个工作簿合并和拆分
  6. 计算机网络与网络管理 基础知识
  7. java execute、executeQuery和executeUpdate之间的区别
  8. 决策树之CART 算法(回归树,分类树)
  9. 电脑重装系统失败无法开机怎么办如何解决
  10. 算法(并查集--合并集合)