因为UEditor原生上传文件和图片的方式是上传到项目路径下,那重新部署项目,原来上传的文件和图片就会消失或者被覆盖,所以, 这里结合
ueditor1.4.3完整源码下载:
链接:https://pan.baidu.com/s/13dTN9ZtfL3EJsogimzy22A
提取码:9vtg
修改步骤:
1,在配置文件“ueditor/jsp/config.json”里添加 saveRootPath,修改 imageUrlPrefix 的值,这个链接是要指向 绝对根路径,用于访问图片或文件
"saveRootPath": "F:\\java\\uploads", /* 文件和图片上传绝对根路径*/ /* 上传图片配置项 */ "imageActionName": "uploadimage", /* 执行上传图片的action名称 */ "imageFieldName": "upfile", /* 提交的图片表单名称 */ "imageMaxSize": 2048000, /* 上传大小限制,单位B */ "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */ "imageCompressEnable": true, /* 是否压缩图片,默认是true */ "imageCompressBorder": 1600, /* 图片压缩最长边限制 */ "imageInsertAlign": "none", /* 插入的图片浮动方式 */ "imageUrlPrefix": "/uploads", /* 图片访问路径前缀 */ "imagePathFormat": "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */ /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */ /* {time} 会替换成时间戳 */ /* {yyyy} 会替换成四位年份 */ /* {yy} 会替换成两位年份 */ /* {mm} 会替换成两位月份 */ /* {dd} 会替换成两位日期 */ /* {hh} 会替换成两位小时 */ /* {ii} 会替换成两位分钟 */ /* {ss} 会替换成两位秒 */ /* 非法字符 \ : * ? " < > | */ /* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
另外记得要修改 ueditor.config.js文件中
//为编辑器实例添加一个路径,这个不能被注释 UEDITOR_HOME_URL: URL // 服务器统一请求接口路径 , serverUrl: URL + "jsp/controller.jsp"
2. 修改package com.baidu.ueditor.ConfigManager.java
conf.put( "savePath", savePath ); conf.put( "rootPath", this.rootPath ); conf.put("saveRootPath",this.jsonConfig.getString("saveRootPath")); return conf;
3. 修改package com.baidu.ueditor.upload.BinaryUploader.java
//String physicalPath = (String) conf.get("rootPath") + savePath; String physicalPath = (String)conf.get("saveRootPath") + savePath;
4. 将JAVA代码全部编译[顺便说下我的方法: 直接在idea的动态项目下建立com.baidu.ueditor包, 将JAVA源代码拷贝进去, 运行项目,所有JAVA源代码自动编译]
5, 通过命令jar cvf ueditor-1.1.2.jar ./com 进行打包
这样 我们就把 原来的相对路径改成了我们想要的绝对路径了
ueditor.jar重新编译打包文件如下:
ueditor文件版本1.4.3.3, 其它文件都不变