fegin使用文件上传

如果项目中使用fegin 需要用 注解 @RequestPart 来接收文件

步骤:

maven

 <dependency>    
    <groupId>io.github.openfeign.form</groupId>    
    <artifactId>feign-form-spring</artifactId>    
    <version>3.2.2</version>    
  </dependency>    
  <dependency>    
      <groupId>io.github.openfeign.form</groupId>    
      <artifactId>feign-form</artifactId>    
      <version>3.2.2</version>    
  </dependency>
  

client代码

@FeignClient(name ="parts-business-commodity-spu/spu_import_excel",configuration = SpuImportForExcelClient.FeignMultipartSupportConfig.class)
public interface SpuImportForExcelClient   {

    /**
     * @Description: 通过excel批量添加商品
     * @param: [MultipartFile]
     * @return: net.tycmc.parts.service.common.util.ApiResult<java.lang.Void>
     * @Auther: zhangxinhao
     * @date: 2019/2/21 13:56
     */
     @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces ={MediaType.APPLICATION_JSON_UTF8_VALUE})
     ApiResult<Void> insertSpuForExcel(@RequestPart(value = "file") MultipartFile multipartFile);

    class FeignMultipartSupportConfig {

        @Bean
        public Encoder multipartFormEncoder() {
            return new SpringFormEncoder();
        }

        @Bean
        public feign.Logger.Level multipartLoggerLevel() {
            return feign.Logger.Level.FULL;
        }
    }
}

引用 :
https://blog.csdn.net/hewei_bj/article/details/80135487

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值