ueditor上傳路徑改成絕對路徑


 由於ueditor默認是上傳到項目的根目錄下,

重新部署項目之前上傳的文件會被清空,所以需要將文件保存到項目目錄之外。

方法如下:

 

① config.json新增配置:"saveRootPath": "d:/data/"

/* 前后端通信相關的配置,注釋只允許使用多行方式 */
{
    "saveRootPath": "d:/data/", /* 文件和圖片上傳絕對根路徑*/
    /* 上傳圖片配置項 */
    "imageActionName": "uploadimage", /* 執行上傳圖片的action名稱 */
    "imageFieldName": "upfile", /* 提交的圖片表單名稱 */
    "imageMaxSize": 52428800, /* 上傳大小限制,單位B,最大50MB */
    "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上傳圖片格式顯示 */
    "imageCompressEnable": true, /* 是否壓縮圖片,默認是true */
    "imageCompressBorder": 1600, /* 圖片壓縮最長邊限制 */
    "imageInsertAlign": "none", /* 插入的圖片浮動方式 */
    "imageUrlPrefix": "/data", /* 圖片訪問路徑前綴 */ "imagePathFormat": "/ueditor/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */

 

② 修改ueditor-1.1.2.jar 中的源碼

 

 

在ConfigManager.getConfig方法中新增配置:conf.put("saveRootPath", this.jsonConfig.getString("saveRootPath"));

public Map<String, Object> getConfig(int type) {
        Map<String, Object> conf = new HashMap<String, Object>();
        String savePath = null;
        switch (type) {
        case 4:
            //省略
        case 1:
            //省略
        case 3:
            //省略
        case 2:
            //省略
        case 5:
            //省略
        case 7:
            //省略
        case 6:
            //省略
        }
        conf.put("savePath", savePath);
        conf.put("rootPath", this.rootPath);
        conf.put("saveRootPath", this.jsonConfig.getString("saveRootPath")); return conf;
    }

將BinaryUploader.save方法中的 rootPath 修改為 saveRootPath

//String physicalPath = String.valueOf(conf.get("rootPath")) + savePath;
String physicalPath = String.valueOf(conf.get("saveRootPath")) + savePath;

----------------------經過以上修改,即可上傳文件到自定義到絕對路徑

 

但是會出現無法預覽的問題

方案1,在tomcat的server.xml中新增虛擬映射地址:<Context docBase="D:/data" path="/data" reloadable="true"/>

<?xml version="1.0" encoding="UTF-8"?>

      <!-- 省略 -->
  
      <Context docBase="ds-eop-war" path="/ds-plan-web" reloadable="true" source="org.eclipse.jst.jee.server:ds-eop-war"/>
      <Context docBase="D:/dssystem" path="/dssystem" reloadable="true"/>
      </Host>
    </Engine>
  </Service>
</Server>

然后重啟tomcat。 無法預覽的問題就此解決

 

方案2  ?


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM