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

    xiaoxiao2021-04-12  34

    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", /* 图片访问路径前缀-要文件服务器的外网地址 */
    转载请注明原文地址: https://ju.6miu.com/read-668253.html

    最新回复(0)