1. 程式人生 > >百度UEditor自定義上傳檔案儲存路徑(補充)

百度UEditor自定義上傳檔案儲存路徑(補充)

上一篇百度UEditor自定義上傳檔案儲存路徑發表後,再解決了線上管理、線上圖片和線上附件功能不能使用的問題。

需要修改FileManager類:

註釋掉的程式碼是原來jar包的程式碼,不再需要,可以刪除掉。

    //private String dir = null;
    private String saveDir = null;
    private String saveRootPath;
    //private String rootPath = null;
    private String[] allowFiles = null;
    private int count = 0
; public FileManager(Map<String, Object> conf) { this.saveRootPath = (String)conf.get("saveRootPath"); //this.rootPath = (String)conf.get("rootPath"); //this.dir = this.rootPath + (String)conf.get("dir"); this.saveDir = this.saveRootPath + (String)conf.get("dir"
); this.allowFiles = this.getAllowFiles(conf.get("allowFiles")); this.count = ((Integer)conf.get("count")).intValue(); } public State listFile(int index) { //File dir = new File(this.dir); File dir = new File(this.saveDir); ... } private State getState
(Object[] files) { ... fileState.putInfo("url", this.getPath(file)); ... } private String getPath(File file) { String path = PathFormat.format(file.getAbsolutePath()); return path.replace(this.saveRootPath, "/"); }

修改後的效果:
圖1
圖2
圖3

如果需要用到抓取遠端圖片功能,還需要修改ImageHunter類:

private String filename = null;
    private String savePath = null;
    private String saveRootPath;
    private List<String> allowTypes = null;
    private long maxSize = -1L;
    private List<String> filters = null;

    public ImageHunter(Map<String, Object> conf) {
        this.filename = (String)conf.get("filename");
        this.savePath = (String)conf.get("savePath");
        this.saveRootPath = (String)conf.get("saveRootPath");
        this.maxSize = ((Long)conf.get("maxSize")).longValue();
        this.allowTypes = Arrays.asList((String[])conf.get("allowFiles"));
        this.filters = Arrays.asList((String[])conf.get("filter"));
    }

    public State captureRemoteData(String urlStr) {
        ...
        String physicalPath = this.saveRootPath + savePath;
        ...
    }

不過非常抱歉,該功能沒有測試,因為不知道該怎麼使用。

如果需要前臺頁面顯示ueditor儲存文章的樣式,需要在頁面上加入:

圖4

<script src="${request.contextPath}/static/js/shCore.js"></script>
<script type="text/javascript">
    SyntaxHighlighter.all();
</script>
<link href="${request.contextPath}/static/css/shCoreDefault.css" rel="stylesheet">

否則一些樣式沒有效果。