feign调用上传文件报错

2022-07-28 08:55:13

最近代码升级,springcloud1.x版本升级为2.x版本,同时feign变成了openfeign,业务上是从a服务调用b服务接口再去调用c服务。

发现文件传不上去,a服务就报错com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile["inputStream"]->java.io.FileInputStream["fd"])

排查问题后,在b服务接口加上参数

consumes = MediaType.MULTIPART_FORM_DATA_VALUE

示例接口如下:

@RequestMapping(value = "/importFile", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    BaseResult<Void> importProductTxt(@RequestPart(value = "file", required = false)  MultipartFile file, @RequestParam("filename") String filename);

还遇到一个上传文件的接口,报错HttpMediaTypeNotAcceptableException Could not find acceptable representation

是因为单文件上传的时候,要用@RequestPart注解

  • 作者:qiuqiucatcat
  • 原文链接:https://blog.csdn.net/weixin_32896095/article/details/124962657
    更新时间:2022-07-28 08:55:13