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路径

 

转载于:https://www.cnblogs.com/skyLogin/p/7505894.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值