当前位置:网站首页>Some problems of feign transferring multipartfile
Some problems of feign transferring multipartfile
2022-06-26 10:43:00 【MervynLammm】
Feign transmission MultipartFile Some of the problems
File turn MultipartFile
pom.xml
<!-- https://mvnrepository.com/artifact/org.springframework/spring-mock -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
</dependency>
public static MultipartFile getMultipartFile(String fileName, File file) throws IOException {
return new MockMultipartFile(fileName, file.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(), new FileInputStream(file));
}
Report errors Current request is not a multipart request、Content type ‘’ not supported
- @PostMapping Set up consumes = MediaType.MULTIPART_FORM_DATA_VALUE
- Use @RequestPart(), Out of commission @RequestParam()
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResultBody upload(@RequestPart(value = "file") MultipartFile file);
Report errors Required request part ‘file’ is not present
configuration
@Configuration
public class UploadFeignConfig {
@Bean
public Encoder multipartFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(new ObjectFactory<HttpMessageConverters>() {
@Override
public HttpMessageConverters getObject() throws BeansException {
return new HttpMessageConverters(new RestTemplate().getMessageConverters());
}
}));
}
}
FeignClient
@FeignClient(value = FileConstants.FILE_SERVER, configuration= UploadFeignConfig.class)
public interface FileServiceClient extends IFileServiceClient {
@Override
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResultBody upload(@RequestPart(value = "file") MultipartFile file);
}
边栏推荐
- Tape library simple record 1
- Oracle sqlplus query result display optimization
- How to start the learning journey of webrtc native cross platform development?
- 开发者,微服务架构到底是什么?
- 【软件项目管理】期末复习知识点整理
- Allocation of heap memory when creating objects
- Progressive Web 应用程序PWA是应用程序开发的未来
- 3行3列整形二维数组,求对角之和
- Little red book - Summary of internal sales spike project
- 【無標題】
猜你喜欢

MySQL第七次作业-更新数据

MySQL第十四次作业--电子商城项目

Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
![[echart] II. User manual and configuration item reading notes](/img/03/fa87e5b8f8d23381ea6923d507f250.jpg)
[echart] II. User manual and configuration item reading notes

MySQL第十三次作业-事务管理

【Leetcode】76. Minimum covering substring

Record the handling of oom problems caused by too many threads at one time

Cmake / set command

MySQL 12th job - Application of stored procedure

MySQL第十一作业-视图的应用
随机推荐
See how I store integer data in the map < string, string > set
哪些PHP开源作品值得关注
Index summary of blog articles -- Industrial Internet
Allocation de mémoire tas lors de la création d'objets
MySQL 13th job - transaction management
Vscode environment setup: synchronous configuration
When will JVM garbage collection enter the older generation
[sans titre]
118. Yanghui triangle
MySQL第五章总结
How to change the QR code material color of wechat applet
Postman入门教程
String constant pool, class constant pool, and runtime constant pool
Procedure Call Standard
MySQL第十四次作业--电子商城项目
MySQL第四章总结
DataBinding使用与原理分析
VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
Idea remote debugger
The sixth MySQL job - query data - multiple conditions