I\'m trying to accomplish a multipart file upload using feign, but I can\'t seem to find a good example of it anywhere. I essentially want the HTTP request to turn out simil
If you are already using Spring Web, you can try my implementation of a Feign Encoder that is able to create Multipart requests. It can send a single file, an array of files alongwith one or more additional JSON payloads. Here is my test project. If you don't use Spring, you can refactor the code by changing the encodeRequest method in FeignSpringFormEncoder.
No, you don't. You just need to define a kind of proxy interface method, specify the content-type as: multipart/form-data and other info such as parameters required by the remote API. Here is an example:
public interface FileUploadResource {
@RequestLine("POST /upload")
@Headers("Content-Type: multipart/form-data")
Response uploadFile(@Param("name") String name, @Param("file") File file);
}
The completed example can be found here: File Uploading with Open Feign
For spring boot 2 and spring-cloud-starter-openfeign use this code:
@PostMapping(value="/upload", consumes = "multipart/form-data" )
QtiPackageBasicInfo upload(@RequestPart("package") MultipartFile package);
You need to change @RequestParam to @RequestPart in the feign client call to make it work, and also add consumes to the @PostMapping.