spring-cloud-gateway: [Spring Cloud Gateway MVC] Multipart data missing
Describe the bug
After routing multipart/form-data through gateway mvc, downstream service receive request but without multipart file.
I looked into code of gateway and in RestClientProxyExchange we have
@Override
public ServerResponse exchange(Request request) {
return restClient.method(request.getMethod()).uri(request.getUri())
.headers(httpHeaders -> httpHeaders.putAll(request.getHeaders()))
.body(outputStream -> copyBody(request, outputStream))
.exchange((clientRequest, clientResponse) -> doExchange(request, clientResponse), false);
}
there is not copy multipart data from original request.
Example route:
@Bean
fun dataStorageFileUpload(): RouterFunction<ServerResponse> {
val servicesUrl = services.url!!
Objects.requireNonNull(servicesUrl["dataStorageService"], "Data storage service url is empty")
return GatewayRouterFunctions.route("dataStorageFileUpload")
.PUT("/storage/file/**", http(servicesUrl["dataStorageService"]))
.before(BeforeFilterFunctions.stripPrefix(1))
.filter(HandlerFilterFunction.ofRequestProcessor(authenticationPopular))
.after(AfterFilterFunctions.removeResponseHeader(GROUP_HEADER))
.after(AfterFilterFunctions.removeResponseHeader(HttpHeaders.AUTHORIZATION))
.after(AfterFilterFunctions.removeResponseHeader(TOKEN_HEADER))
.build()
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 18 (6 by maintainers)
Commits related to this issue
- Sets spring.servlet.multipart.enabled to false by default. Fixes gh-3527 — committed to spring-cloud/spring-cloud-gateway by spencergibb 2 years ago
- Re-enables MultipartEnvironmentPostProcessor Closes gh-3527 — committed to spring-cloud/spring-cloud-gateway by spencergibb 2 years ago
- Re-enables MultipartEnvironmentPostProcessor Closes gh-3527 — committed to spring-cloud/spring-cloud-gateway by spencergibb 2 years ago
- Sets spring.servlet.multipart.enabled to false by default. Fixes gh-3527 — committed to Been24/spring-cloud-gateway by spencergibb 2 years ago
- Re-enables MultipartEnvironmentPostProcessor Closes gh-3527 Signed-off-by: ubest <zhangfeng@sipg.com.cn> — committed to Been24/spring-cloud-gateway by spencergibb 2 years ago
In the meantime, the following did the trick (to put ONLY in gateway service, not in all micro-services):
application.properties
See https://codevup.com/issues/2025-01-25-spring-gateway-mvc-missing-multipart-data/
Hi to you all,
We just faced this issue too, using org.springframework.cloud:spring-cloud-starter-gateway-mvc:4.2.0; and solved it by just disabling the multipart resolver provided by spring like this:
spring.servlet.multipart.enabled=falseDoing it prevented the gateway to process the multipart data, this caused it to be still available on the downstream services.
Thank you to the people who gave hints, it helped me on my way to this “most non intuitive” solution 😃
Again, I’d appreciate anyone that could try snapshots.
We had the same issue.
I can provide an example here: https://github.com/sapo-di/gateway-mvc-test/
You need to run the ProxyApplication and can use the
forward-mutlipart.httpfor an example request againsthttp://localhost:8080/multipartThe produces exception is:
@spencergibb I have tested
4.3.0-SNAPSHOTversion, and multipart can now be passed to downstream services correctly.Thanks for the fix!