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

1、环境

ueditor.jar版本 为1.1.2

2、场景

1、在webapp开发中,需要将富文本中的文件存储到单独的文件服务器,而ueditor默认只能在web项目根路径下。
2、ueditor生成的富文本里图片路径是相对路径,因而在app端无法显示

3、快速解决方法

4、解决步骤

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

2、按官方文档将jsp项目导入到eclipse或iead中并正常运行 http://fex.baidu.com/ueditor/#server-deploy

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

此时的项目结构:
此时的项目结构

4、ueditor-xxx.jar的源码就不解析了。代码不多。大家大致看下就能懂了。

5、修改方法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, Object> conf)方法中的
    String physicalPath = rootPath + savePath;
改成
    String physicalPath = getPhysicalPath(conf, savePath, rootPath);

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

8、大功告成

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

"externalStoragePath":"/opt/fileService/img/",/*文件服务器路径*/

"imageUrlPrefix": "http://xxx.xxx.xxx:8080/xxx/xxx", /* 图片访问路径前缀-要文件服务器的外网地址 */
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值