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);
}
}