• 通过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);
    }
  • 相关阅读:
    随身wifi 备份篇
    B站跳OP OD
    android系统
    华为悦盒EC6180V9 刷 ubuntu20.4_nas
    windous 常用命令
    随身wifi debian篇
    随身WiFi 面具篇
    杀掉多线程id
    pytorch 命令
    英伟达命令
  • 原文地址:https://www.cnblogs.com/niudaben/p/13229941.html
Copyright © 2020-2023  润新知