springboot 1.5.1
公司项目升级springboot由1.5.1升级到2.1.2.RELEASE,cloud版本也升级到G版本。突然发现文件上传失效。。。之前解决掉的问题又再次出现
问题收集如下:
1.Feign library does not support Multipart requests
2. The current request is not a multipart request
3. the request was rejected because no multipart boundary was found
如果使用的是sprignboot 2.0、cloud F版本以下,则可以通过
feign文件上传 解决
springboot 2.1.2
升级G版本后,
消费方需要删除掉原来引用的,因为该版本已经适配了feign-form和feign-form-spring,无需再次引入
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.3.0</version>
</dependency>
消费方增加配置文件:
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.3.0</version>
</dependency>
服务提供方:
使用@RequestPart接收参数,还需定义consumes
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Result<List<FileBO>> upload(@RequestPart("file") MultipartFile [] multipartFiles ) throws IOException;