wangEditor后台上传成功但是,前端提示上传图片失败

遇到errno=undefined错误

在上传图片成功,但是却会触发fail并显示errno=undefined的话说明后台放回的字段中没有errno需要和后台沟通并加上此字段,还有若data有问题则需要与后台沟通,data应该是一个数组,存储着图片的值的路径

注意    不是 error,是  errno

此处贴上我自己的wangEditor处理后台逻辑

@PostMapping("/editor/upload")
    public Dict editorUpload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename(); //文件的原始名称
        String projectPath = System.getProperty("user.dir"); 
        //System.out.println("projectPath"+projectPath);// in linux   /home/server/mooc/java
        String filesPath = projectPath + File.separator + "files"; //文件存储的目录 D:\..\Mooc\files
        String fileRealPath = filesPath + File.separator + originalFilename; //D:\..\files\abc.png
        File saveFile = new File(fileRealPath);
        if(!saveFile.getParentFile().exists()){
            saveFile.getParentFile().mkdirs(); //如果当前文件的父级目录不存在,就创建
        }
        if(saveFile.exists()){
            fileRealPath = filesPath + File.separator + System.currentTimeMillis() + "_" + originalFilename;
            saveFile = new File(fileRealPath); //D:\..\files\12313132131_abc.png
        }
        file.transferTo(saveFile);  //存储文件到本地的磁盘里面去
        String url = "http://" + ip + ":" +port + "/file/download/" + originalFilename;
        //我们要返回一个json数据,可以通过Hutool提供的dict,dict实际上是一个map
        Dict dict = Dict.create().set("errno", 0).set("data", CollUtil.newArrayList(Dict.create().set("url",url)));
        return dict;  //返回文件的链接,这个链接就是文件的下载地址
    }

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-09 15:40:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-09 15:40:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-09 15:40:02       82 阅读
  4. Python语言-面向对象

    2024-04-09 15:40:02       91 阅读

热门阅读

  1. 搞懂了XML!

    2024-04-09 15:40:02       35 阅读
  2. 在Linux删除几天前的日志文件

    2024-04-09 15:40:02       34 阅读
  3. Spring与Spring Boot的区别和联系

    2024-04-09 15:40:02       35 阅读
  4. html自定义禁用状态下且已选中的checkbox

    2024-04-09 15:40:02       33 阅读
  5. 对称排序(蓝桥杯)

    2024-04-09 15:40:02       35 阅读
  6. 软件版权登记的条件

    2024-04-09 15:40:02       37 阅读
  7. Go语言中如何实现多态

    2024-04-09 15:40:02       38 阅读
  8. Qt-Mat转QImage

    2024-04-09 15:40:02       29 阅读
  9. leetcode回忆法-1两数之和

    2024-04-09 15:40:02       27 阅读
  10. 【c++&leetcode】1. Two Sum

    2024-04-09 15:40:02       33 阅读
  11. [LeetCode][LCR131]砍竹子 I——推测规律

    2024-04-09 15:40:02       34 阅读
  12. 地理处理和空间分析的关键技巧

    2024-04-09 15:40:02       31 阅读
  13. vs mfc未加载mfc140u导致无法启动

    2024-04-09 15:40:02       28 阅读