1.添加依赖,支持SpringEncoder
<dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form</artifactId> <version>3.4.1</version> </dependency> <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form-spring</artifactId> <version>3.4.1</version> </dependency>
2.将SpringFormEncoder的默认处理encoder配置为SpringEncoder
@Configuration public class FeignMultipartSupportConfig { @Bean public Encoder multipartFormEncoder(ObjectFactory<HttpMessageConverters> messageConverters) { return new SpringFormEncoder(new SpringEncoder(messageConverters)); } }
3.编写client
@FeignClient(value = "****", fallbackFactory = UploadClientFallbackFactory.class , configuration = FeignMultipartSupportConfig.class ) public interface UploadClient { /** * 上传图片文件 * * @param file * @return */ @PostMapping(value = "/tbk/feedback/upload", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) BaseResponse<String> uploadImage(@RequestPart("file") MultipartFile file); }