Feign接口文件上传

1.client子模块pom中导入3个依赖包

<dependency>
   <groupId>io.github.openfeign.form</groupId>
   <artifactId>feign-form</artifactId>
   <version>3.0.3</version>
</dependency>
<dependency>
   <groupId>io.github.openfeign.form</groupId>
   <artifactId>feign-form-spring</artifactId>
   <version>3.0.3</version>
</dependency>
<dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.3.3</version>
</dependency>

2. interface FileFeignClient,配置

@FeignClient(name = "fileTransfer", url = "${fileTransfer.service.url}", configuration = FileFeignClient.MultipartSupportConfig.class)
public interface FileFeignClient {

3.interface FileFeignClient,配置

    @Configuration
    class MultipartSupportConfig {
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }
}

4.interface FileFeignClient 中的接口,配置

@PostMapping(value = "/zip/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
BaseVO<FileTransferVo> uploadZip(@RequestBody MultipartFile file);

5.public class FileController {xxx}中的接口,配置

@PostMapping(value = "/zip/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ApiOperation(value = "上传压缩包")
public BaseVO uploadZip(@ApiParam(value = "压缩包", required = true) @RequestBody MultipartFile file) throws Exception {xxx}
发布了82 篇原创文章 · 获赞 18 · 访问量 1万+
展开阅读全文

feign MultipartFile fastdfs跨服务调用文件上传

11-17

基本情况是: 不是通过浏览器请求,是微服务中在服务启动后自动把制定目录下的文件,通过feign调用文件上传接口,将文件保存到服务器。 参考了各位的建议之后,还是报相同的错误。 贴出一段idea中的异常信息: feign.FeignException: status 500 reading RemoteFdfsService#fdfsUpload(MultipartFile); content: {"msg":"Current request is not a multipart request","code":1,"data":null} at feign.FeignException.errorStatus(FeignException.java:60) at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:89) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:143) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:77) at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:107) at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302) at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298) at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46) at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) 调用部分代码(接口需要的是MultipartFile的文件参数) String filePath = "F:\\mac\\pic\\20181113184344_type[0]_ItsPlate.jpg"; File file = new File(filePath); FileInputStream fileInputStream = new FileInputStream(file); MultipartFile multipartFile = new MockMultipartFile(file.getName(), fileInputStream); String url = remoteFdfsService.fdfsUpload(multipartFile); feign: @FeignClient(value = ServiceNameConstant.FDFS_SERVICE, configuration = RemoteFdfsService.MultipartSupportConfig.class, fallbackFactory = RemoteFdfsServiceFallbackFactory.class) public interface RemoteFdfsService { /** * 上传图片并且生成缩略图 * @param file * @return */ @PostMapping(value = "/fdfs/upload_image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) String fdfsUploadImage(@RequestPart(value = "file") MultipartFile file); /** * 引用配置类MultipartSupportConfig.并且实例化 */ @Configuration class MultipartSupportConfig { @Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(); } } } 烦请各路上仙指点一二,多谢。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览