• Spring MVC -- UEditor 编辑器整合 上传图片至外部文件夹(非项目文件夹)


     上传图片到外部储存,回显图片

    下载全部UEditor资源源码

    config.json配置 
    config.json中添加如下属性 (一定要添加此属性):

     "physicsPath":"d:/resource", 

    修改源码:

    physicsPath不为空串时: (默认)

    文件存放路径:physicsPath + imagePathFormat 
    返回给浏览器路径:imageUrlPrefix + imagePathFormat

    physicsPath为空串时:

    文件存放路径:项目根路径 + imagePathFormat 
    返回给浏览器路径:imageUrlPrefix + imagePathFormat 
    *此时imageUrlPrefix 应设置为项目名

     
    仅仅完成上面的配置是不够的,在使用中会图片是上传后是无法预览的,既然文件放在项目路径外部,想通过当前项目来访问这些图片不是好的方式; 

    修改引入的 ueditor.all.js 

    @RequestMapping(value = "/uEditor/image")
        public void image(String fileName, HttpServletResponse response) throws IOException {
            File userPhotoFile = new File("d:/home/resource" + fileName);
            response.setContentType("image/png");
            response.setContentLength((int) userPhotoFile.length());
            response.setStatus(HttpServletResponse.SC_OK);
            try (OutputStream output = response.getOutputStream()) {
                FileUtils.copyFile(userPhotoFile, output);
                output.flush();
            }
        }
    

      

    当然啦,还需要修改多图上传的图片src路径

  • 相关阅读:
    [面试没答上的问题1]http请求,请求头和响应头都有什么信息?
    模拟进度条发现的彩蛋
    实现JavaScript forEach
    JavaScript实现动画效果
    Contents Of My Blogs
    阅读笔记-拍出好照片的30个构图基本功
    阅读笔记-李鸿章传
    阅读笔记-人性的弱点
    阅读笔记-XWord:未来进化
    阅读笔记-活法
  • 原文地址:https://www.cnblogs.com/skyLogin/p/7505894.html
Copyright © 2020-2023  润新知