微服务之间文件流发送

package com.quanwei.wlanscope_wechat_information_treasure.config;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @date 2019-8-21
 *
 * <p>微服务之间通过Feign进行文件互传的配置类</p>
 * <p>添加feign的扩展包,并自定义编码</p>
 *
 * <p>添加依赖
 * <!--开启feign(集成了ribbon和hystrix)-->
 * <dependency>
 * <groupId>org.springframework.cloud</groupId>
 * <artifactId>spring-cloud-starter-openfeign</artifactId>
 * </dependency>
 * <!--feign底层替换httpClient-->
 * <dependency>
 * <groupId>io.github.openfeign</groupId>
 * <artifactId>feign-httpclient</artifactId>
 * </dependency>
 * <!--feign扩展包版本太高 已经出现问题,此处使用3.0.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>
 * <p>
 * </>
 * <p>
 * 调用示例
 * @FeignClient(value = "wlanscope-oss-server")
 * public interface TestUploadFileService {
 * @PostMapping(value = "/oss-server/file/test-upload-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
 * String test(@RequestPart("file") MultipartFile file);
 * }
 * <i> consumes = MediaType.MULTIPART_FORM_DATA_VALUE,此处必须指明类型</>
 *
 * <p>文件接收接口
 * public String testAccecptFile(@RequestPart ("file")MultipartFile multipartFile)
 * 如此接口即可
 * </p>
 *
 * <p>
 * 调用feign 接口示例
 * public String test() {
 * MultipartFile multipartFile = new MockMultipartFile("file", "123", MediaType.MULTIPART_FORM_DATA_VALUE, "234.txt".getBytes(StandardCharsets.UTF_8));
 * <i>由于文件接收接口 固定参数为file,所以此处的第一个参数(文件名)必须为file</i>
 * 构造函数列表含义:文件名(文件接收接口定义的参数名)、原始文件名、请求类型、文件内容
 * String msg = testUploadFileService.test(multipartFile);
 * return msg;
 * }
 *
 * </p>
 */
@Configuration
public class MultipartSupportConfig {
    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder();
    }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值