question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FeignClient: Multipart requests only work with @PathVariable parameters.

See original GitHub issue

The 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 nameParams.

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 formParams, 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 MultiPartFiles 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:closed
  • Created 8 years ago
  • Comments:36 (6 by maintainers)

github_iconTop GitHub Comments

14reactions
cbornetcommented, Jul 5, 2016

👍 for MultipartFile support

3reactions
spencergibbcommented, Oct 31, 2019

@antemooo please stop commenting the same thing on multiple issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feign multipart with Json request part - java - Stack Overflow
Managed to solve this by replacing the feign-form PojoWriter. By default it's serializing each field of an object as a separate part.
Read more >
Sending multipart requests using Spring Boot and Feign
The intention of this article is to provide help to all people struggling with sending multipart requests using Spring Boot and Feign.
Read more >
A brand new website interface for an even better experience!
FeignClient : Multipart requests only work with @PathVariable parameters.
Read more >
OpenFeign/feign - application/json - Gitter
Hi there, is it possible to make multipart/related requests using feign?Is there encoder created particularly for this type of request?
Read more >
Spring Cloud OpenFeign
DELETE, value = "/stores/{storeId:\\d+}") void delete(@PathVariable Long ... Each feign client is part of an ensemble of components that work together to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found