File 转 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>
publicstatic MultipartFilegetMultipartFile(String fileName, File file)throws IOException{returnnewMockMultipartFile(fileName, file.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(),newFileInputStream(file));}
报错 Current request is not a multipart request、Content type ‘’ not supported
- @PostMapping设置 consumes = MediaType.MULTIPART_FORM_DATA_VALUE
- 使用@RequestPart(),不能使用@RequestParam()
@PostMapping(value="/upload", consumes= MediaType.MULTIPART_FORM_DATA_VALUE) ResultBodyupload(@RequestPart(value="file") MultipartFile file);
报错 Required request part ‘file’ is not present
configuration
@ConfigurationpublicclassUploadFeignConfig{@Beanpublic EncodermultipartFormEncoder(){returnnewSpringFormEncoder(newSpringEncoder(newObjectFactory<HttpMessageConverters>(){@Overridepublic HttpMessageConvertersgetObject()throws BeansException{returnnewHttpMessageConverters(newRestTemplate().getMessageConverters());}}));}}
FeignClient
@FeignClient(value= FileConstants.FILE_SERVER, configuration= UploadFeignConfig.class)publicinterfaceFileServiceClientextendsIFileServiceClient{@Override@PostMapping(value="/upload", consumes= MediaType.MULTIPART_FORM_DATA_VALUE) ResultBodyupload(@RequestPart(value="file") MultipartFile file);}
热门文章
- 3月2日22.6M/S|Shadowrocket/Clash/V2ray/SSR免费节点每天更新订阅链接,翻墙机场推荐分享
- C/C++内存申请函数总结
- 酒精消毒液哪个牌子好用(酒精消毒液哪个牌子好一点)
- SpringBoot之HandlerInterceptor拦截器的使用
- SpringBoot自定义控制层参数解析_在线工具
- 做狗粮有市场吗 做狗粮有市场吗现在
- 动物疫苗去哪里买的啊多少钱(动物疫苗证去哪里办怎么办)
- 3月11日19.9M/S|Shadowrocket/SSR/Clash/V2ray免费节点每天更新订阅链接,翻墙机场推荐分享
- 宠物产品定位(宠物店产品定位)
- 武汉宠物领养中心官网地址电话(武汉宠物猫领养中心)