当前位置:网站首页>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);
}
边栏推荐
- Dynamic library connection - symbol conflict - global symbol intervention
- MySQL第十三次作业-事务管理
- Global and Chinese markets of children's electronic thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
- SQL Server foundation introduction collation
- Threading model in webrtc native
- Allocation of heap memory when creating objects
- Establishment of smart dialogue platform for wechat official account
- See how I store integer data in the map < string, string > set
- AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D
- [echart] II. User manual and configuration item reading notes
猜你喜欢

Renesas electronics launched a complete intelligent sensor solution for Internet of things applications

开发者,微服务架构到底是什么?

118. Yanghui triangle

Allocation of heap memory when creating objects

Vscode environment setup: synchronous configuration

String constant pool, class constant pool, and runtime constant pool

【Leetcode】76. Minimum covering substring

Flutter and native communication (Part 1)

Basic string operations in C

MySQL seventh job - update data
随机推荐
Record the handling of oom problems caused by too many threads at one time
Oracle sqlplus 查询结果显示优化
VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
看我在Map<String, String>集合中,存入Integer类型数据
MySQL 13th job - transaction management
MySQL seventh job - update data
磁带库简单记录1
When will JVM garbage collection enter the older generation
The fourteenth MySQL operation - e-mall project
SSH, SCP command appears permission denied, please try again solution
[untitled]
[difficult and miscellaneous diseases] @transitional failure summary
MySQL第十四次作业--电子商城项目
MySQL job 11 - application de la vue
Dynamic library connection - symbol conflict - global symbol intervention
echo $?
3行3列整形二维数组,求对角之和
Selection of webrtc video codec type VP8 H264 or other? (openh264 encoding, ffmpeg decoding)
904. fruit baskets
MySQL第六章总结