Feign 文件上传配置

FeignClient

@FeignClient(name = ServiceConstant.RENREN_OSS_SERVER, configuration = OssFeignClient.MultipartSupportConfig.class)
public interface OssFeignClient {
    /**
     * 文件上传
     * @param file 文件
     * @return  返回路径
     */
    @PostMapping(value = "oss/file/upload", consumes = "multipart/form-data")
    Result<UploadDTO> upload(@RequestPart("file") MultipartFile file);

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

}

Contorller

@RestController
@RequestMapping("file")
@Api(tags="文件上传")
public class ApiOssController {

    @Autowired
    private OssFeignClient ossFeignClient;
    @PostMapping("upload")
    @ApiOperation(value = "上传文件")
    public Result<UploadDTO> upload(@RequestPart("file") MultipartFile file){
        return ossFeignClient.upload(file);
    }
}

posted @ 2023-07-11 10:34  路暝月  阅读(43)  评论(0编辑  收藏  举报  来源