ueditor 添加支持文件存储到文件服务器

来源:互联网 发布:javascript入门经典pdf 编辑:程序博客网 时间:2024/06/08 17:36

起因

百度富文本ueditor编辑器默认图片,视频,等文件类型的资源会默认上传到系统的部署目录,但是实际开发过程中,大部分的文件是需要上传到ftp或者文件系统上的。这里提供一个扩展ueditor,使上传的附件上传到文件服务器中。

环境

ueditor.jar版本 为1.4.3.3

解决步骤

1、从官网下载jsp版本和完整源码 。http://ueditor.baidu.com/website/download.html

2、按官方文档将jsp项目导入到eclipse或iead中并正常运行 。

3、复制源码目录中\jsp\src\到iead项目源码中、并把ueditor-xxx.jar依赖去掉。。

4、修改方法

com.baidu.ueditor.ConfigManager.getConfig(int type); 

在最加入

conf.put(“externalStoragePath”, this.jsonConfig.optString(“externalStoragePath”));

6、在 com.baidu.ueditor.upload.BinaryUploader类中,添加如下方法取文件存储位置

private static String getPhysicalPath(Map<String, Object> conf, String savePath, String rootPath) {        String externalStoragePath = (String) conf.get("externalStoragePath");        String physicalPath;        if (externalStoragePath != null && externalStoragePath.trim().length() != 0) {            physicalPath = externalStoragePath;        } else {            physicalPath = rootPath;        }        physicalPath += savePath;        return physicalPath;}

将该类save(HttpServletRequest request,Map

String physicalPath = rootPath + savePath;

改成

String physicalPath = getPhysicalPath(conf, savePath, rootPath);

7、将com.baidu.ueditor.upload.Base64Uploader类按上述修改方式进行同样的修改。

8、在ueditor/jsp/config配置中添加

"externalStoragePath":"/opt/fileService/img/",/*文件服务器路径*/"imageUrlPrefix": "http://xxx.xxx.xxx:8080/xxx/xxx", /* 图片访问路径前缀-要文件服务器的外网地址 */
原创粉丝点击