FeignClient: Multipart requests only work with @PathVariable parameters.
See original GitHub issueThe following interface should be enough to handle multipart form requests:
@FeignClient(url = "http://localhost:8080")
public interface SpringFeignTestInterface {
@RequestMapping(value = "/upload/{folder}", method = POST)
public ResponseEntity<UploadInfo> upload(@PathVariable("folder") String folder, @RequestParam("file") MultipartFile file, @RequestParam("metadata") UploadMetadata metadata) ;
}
It doesn’t work, since the @RequestParam
annotation (processed by this code) does not trigger multipart form generation, since it creates nameParam
s.
But if I use @PathVariable
for all parameters, like the following:
@FeignClient(url = "http://localhost:8080")
public interface SpringFeignTestInterface {
@RequestMapping(value = "/upload/{folder}", method = POST)
public ResponseEntity<UploadInfo> upload(@PathVariable("folder") String folder, @PathVariable("file") MultipartFile file, @PathVariable("metadata") UploadMetadata metadata) ;
}
the multipart request is created correctly, since the @PathVariable
parameters that aren’t actually in the URL, are processed as formParam
s, see here.
Please note that at the moment I used my own implementation of Feign Encoder
to build the multipart request correctly.
Maybe this weird behaviour of @PathVariable
should be removed, and @RequestParam
should trigger form creation if it contains MultiPartFile
s or arrays of them.
It would be great to see that Spring Feign could take full advantage of all REST Controller annotations (not to mention @RequestPart
…).
Issue Analytics
- State:
- Created 8 years ago
- Comments:36 (6 by maintainers)
Top GitHub Comments
👍 for MultipartFile support
@antemooo please stop commenting the same thing on multiple issues