Feign 无法直接传递文件参数,需要在client端引入几个依赖
1. 创建服务端
方式与普通的文件上传方法一致
@RestController
@RequestMapping("/producer/upload")
class UploadProducer {
@PostMapping(value = '/upload', consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
String upload(@RequestPart(value = "file") MultipartFile file) {
// ...
return file.originalFilename
}
}
2. 创建client
2.1 需要在客户端引入以下依赖
io.github.openfeign.form:feign-form:3.0.3
io.github.openfeign.form:feign-form-spring:3.0.3
2.2 定义client接口
@FeignClient(name = 'upload', url = '${upload.base-url}', path = '/producer/upload')
interface UploadClient {
@RequestMapping(value = '/upload',