• SpringCloud使用Feign Form实现微服务之间的文件上传


    1.pom依赖

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

    2.MultipartSupportConfig配置类

    @Configuration
    public class MultipartSupportConfig {
        @Autowired
        private ObjectFactory<HttpMessageConverters> messageConverters;
    
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
    }

    3.后端接口改造

    关键字consumes = MULTIPART_FORM_DATA_VALUE

    /**
    * 文件上传接口
    * @param file 上传文件
    * @date 2019-11-19 11:56:40
    **/
    @PostMapping(value = "uploadExamTarget", consumes = MULTIPART_FORM_DATA_VALUE)
    public JsonResult uploadExamTarget(@RequestBody MultipartFile file) {
    return new JsonResult(coreClient.uploadExamTarget(file));
    }

    4.FeignClient接口改造

    引入配置类MultipartSupportConfig,和接口注解consumes = MULTIPART_FORM_DATA_VALUE

    @FeignClient(value = "core-server", configuration = MultipartSupportConfig.class)
    public interface CoreClient {  
      /**
       * 调用core-server服务的文件上传接口
       * @param file 上传文件
      * @date 2019-11-19 11:56:40
      **/
      @RequestMapping(value = "/excel/uploadExamTarget", consumes = MULTIPART_FORM_DATA_VALUE) 
      String uploadExamTarget(@RequestBody MultipartFile file);
    }
  • 相关阅读:
    GPUImage原理
    iOS开发技巧
    iOS如何做出炫酷的翻页效果
    iOS开发CAAnimation详解
    iOS开发CAAnimation类动画, CATransition动画
    iOS开发UUIView动画方法总结
    iOS开发NS_ENUM和NS_OPTIONS区别
    iOS开发SDWebImage源码解析之SDWebImageManager的注解
    iOS开发SDWebImageOptions理解
    Swift-重写(Override)
  • 原文地址:https://www.cnblogs.com/shiblog/p/11888398.html
Copyright © 2020-2023  润新知