Springcloud feign文件上传报错FileUploadException: the request was rejected because no multipart boundary
spring cloud,写了一个图片上传的服务,直接用postman 请求这个服务,是没有问题的,
但是在web层(comsumer层?)用feign去调用这个服务,就报错了,
the request was rejected because no multipart boundary was found,最后查了半天原来是spring版本和feign-form的版本不对应的原因导致的,升级了feign-form的版本,问题解决
<dependencies>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>x.y.z</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>x.y.z</version>
</dependency>
</dependencies>
@FeignClient(name = "feign-service",configuration =MultipartSupportConfig.class)
public interface FeignService{
@RequestMapping(value = "/uploads", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
String uploads(@RequestPart("file") MultipartFile file);
}
public class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}