当前位置:网站首页>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);
}
边栏推荐
- MySQL seventh job - update data
- Enter a positive integer with no more than 5 digits, and output the last digit in reverse order
- Solution to the problem of compilation error due to repeated third-party package names
- Basic string operations in C
- Yarn package management tool
- Pytest configuration file
- echo $?
- 二叉树常见面试题
- 118. Yanghui triangle
- Common interview questions of binary tree
猜你喜欢
Function run time
How to change the QR code material color of wechat applet
Based on Zeng Shen's explanation, the line segment tree is studied again one
開發者,微服務架構到底是什麼?
工程数学概率论统计简明教程第二版复习大纲
JS reverse | four libraries and one platform response data encryption
Call API interface to generate QR code of wechat applet with different colors
MySQL seventh job - update data
Developers, what is the microservice architecture?
Under the double reduction, the amount of online education has plummeted. Share 12 interesting uses of webrtc
随机推荐
Little red book - Summary of internal sales spike project
Small example of SSM project, detailed tutorial of SSM integration
MySQL Chapter 6 Summary
Establishment of smart dialogue platform for wechat official account
Allocation de mémoire tas lors de la création d'objets
Linux下安装Mysql【详细】
MySQL第六次作业-查询数据-多条件
String constant pool, class constant pool, and runtime constant pool
MySQL seventh job - update data
Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
Developers, what is the microservice architecture?
MySQL project 8 summary
Pytest configuration file
Installer MySQL sous Linux [détails]
Leetcode intermediate node of linked list
Express (I) - easy to get started
Yarn package management tool
MySQL 12th job - Application of stored procedure
Servlet learning notes II
Searchview click failure