Multiple @RequestPart not Working

See original GitHub issue

Hi,

Below is my technology stack: Spring Boot --> 2.1.6.RELEASE spring-cloud-starter-openfeign --> 2.1.2.RELEASE feign-form-spring --> 3.3.0

I have following code in my Interface of Rest Controller Implementation

@PostMapping(value = "/files", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    ResponseEntity<Output> createFile(
            @RequestPart("file") MultipartFile file,
            @RequestPart("properties") Map<String, String> properties);

My Feign client just extends this interface and it has Feign Client Annotation like below

@FeignClient(name = "feign-client", url = "${host}/store/v1/", configuration = FeignConfig.class)
public interface StoreClient extends StoreInterface {
}

When I try to start my Spring Boot app, I get below exception

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity au.com.macquarie.bfs.ml.store.v1.StoreClient.createFile(org.springframework.web.multipart.MultipartFile,java.util.Map)

I tried googling and adopting many solutions, but looks like this is not supported yet.

Can some one help me resolve this and get around?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
arbarrecommented, Nov 7, 2019

I’m facing the same issue mentioned by @thekalinga and @mazkozi and would love to see a solution to this…

@thekalinga @MrBogue

If you are still facing the problem, look to the Issue #62 . After reading the issue which provide a solution, I put another solution in the comments. You can directly see it here

Actually I don’t see how it solves the issue exposed here (correct me if I’m wrong, but it doesn’t seem you are dealing with multiple @RequestPart).

2reactions
wakedeercommented, Nov 26, 2020

works! If feign doesn’t sent POJO - just add bean JsonFormWriter in feign configuration:

import org.springframework.cloud.openfeign.support.AbstractFormWriter;
import org.springframework.cloud.openfeign.support.JsonFormWriter;
@Configuration
@ComponentScan
@EnableFeignClients
public class ClientConfiguration {
    @Bean
    public AbstractFormWriter jsonFormWriter() {
        return new JsonFormWriter();
    }
}

Thanks @darrenfoong for the fix: https://github.com/spring-cloud/spring-cloud-openfeign/pull/314

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot Rest Api - Multiple @RequestPart not working ...
I have a Spring Boot 2.4.3 with @RestController public class DemoFeignController { @PutMapping(value = "/document", consumes = MediaType.
Read more >
Multipart Request Handling in Spring - Baeldung
In this tutorial, we'll focus on various mechanisms for sending multipart requests in Spring Boot. Multipart requests consist of sending ...
Read more >
Multipart Requests - Swagger
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file...
Read more >
RequestPart (Spring Framework 6.0.2 API)
Annotation Interface RequestPart ... Annotation that can be used to associate the part of a "multipart/form-data" request with a method argument. Supported method ......
Read more >
Multiple @Requestpart Not Working With Feign Client - ADocLib
Spring Boot Rest Api - Multiple @Requestpart Not Working With Feign Client. Is there anything I can do to make this work? Its...
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