Feign传文件 Failed to parse multipart servlet request
首先看依赖版本,如果springboot版本高于2.0,feign-form-spring的版本最好不低于3.5
看下注解是否是@postMapping,其实跟这关系不是很大
再看下,客户端是否有consumes = MediaType.MULTIPART_FORM_DATA_VALUE
然后继续看这几处是否都有@RequestPart(“file”)注解MultipartFile
接着看feign这个接口中的方法中是否有consumes = MediaType.MULTIPART_FORM_DATA_VALUE,以及@RequestPart(“file”)
最后看下服务提供方是否有@RequestPart(“file”)
代码如下
客户端controller:
@PostMapping(value = "admin-end/plan/detail/read", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void readExcel(@RequestPart("file") MultipartFile file){
feignService.readExcel(file);
}
feign:
@PostMapping(value = "/v1/plan/detail/readExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result<String> readExcel(@RequestPart("file") MultipartFile file);
服务方controller:
@PostMapping("/readExcel")
public void exportExcel(@RequestPart("file") MultipartFile file) throws Exception {
//todo
}
除了传文件,其他参数也可以传递,只需要加对应注解即可,比如
@RequestParam("id") Long id