zoukankan      html  css  js  c++  java
  • 通过Feign上传文件(踩坑)

    通过 feign  调用文件服务提供者接口时,需传输 文件file ,服务调用者有时会报错误:feign.FeignException$BadRequest: status 400 reading  

    服务提供者会报 Required request part 'file' is not present  错误。

    这是因为服务调用者MultipartFile的value跟服务提供者@RequestPart中的value值不一样导致的。

    在服务调用者MultipartFile的value要跟服务提供者的@RequestPart中的value值一样。不然它会抛出400异常!!!

    示例

    服务调用者

    @PostMapping("/xxx/file")
    public xx uploadOrderFilesToOSS(@ApiParam("附件") @RequestParam("file") MultipartFile[] file) {
       return xxxService.uploadOrderFilesToOSS(file);
    }

    Feign

    @PostMapping(value = "/file", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    xxx uploadSigleFile(@RequestParam("path") String path, @RequestPart("file") MultipartFile file);

    服务提供者

    @PostMapping(value = "/file", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public xxx uploadSigleFile(@RequestParam("path") String path, @RequestPart("file") MultipartFile file) {
      return fileService.uploadFileToOSS(path, file);
    }
  • 相关阅读:
    python获取DBLP数据集
    GNUPLOT 画多组柱状图 以及 折线图 以及各种问题的解决方案
    Leetcode 1:two sum
    测试面试之如何测试一个杯子
    C++小总结
    统计‘1’的个数
    C语言小总结
    剑指offer面试题1---赋值运算符函数
    黑盒测试与白盒测试
    软件测试的原则
  • 原文地址:https://www.cnblogs.com/niudaben/p/13229941.html
Copyright © 2011-2022 走看看