Open lonelyleaf opened 3 years ago
Your request is exceeding the default header size limit in WebFlux's multipart support. In a Spring Boot application you can customize that limit using a CodecCustomizer
:
@Bean
CodecCustomizer codecCustomizer() {
return (codecs) -> codecs.defaultCodecs().configureDefaultCodec((codec) -> {
if (codec instanceof MultipartHttpMessageReader) {
HttpMessageReader<Part> partReader = ((MultipartHttpMessageReader) codec).getPartReader();
if (partReader instanceof DefaultPartHttpMessageReader) {
((DefaultPartHttpMessageReader) partReader).setMaxHeadersSize(48 * 1024);
}
}
});
}
I think we should explore making this easier, perhaps via an application property, or at least documenting how to do it. We can use this issue to track that work.
If you don't believe that the header size limit should have been exceeded in this case, please open a Spring Framework issue.
@wilkinsona Thank you , I solved my problem by your reply,though it dosen't work directly.Need to change a little bit in spring boot webflux.
@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer {
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.defaultCodecs().configureDefaultCodec((codec) -> {
if (codec instanceof MultipartHttpMessageReader) {
HttpMessageReader<Part> partReader = ((MultipartHttpMessageReader) codec).getPartReader();
if (partReader instanceof DefaultPartHttpMessageReader) {
((DefaultPartHttpMessageReader) partReader).setMaxHeadersSize(128 * 1024);
}
}
});
}
}
That’s strange as it worked for me. Note that by using @EnableWebFlux
you are disabling all of Boot’s auto-configuration of WebFlux, including applying any CodecCustomizer
beans. Did you already have @EnableWebFlux
somewhere in your app?
@wilkinsona I did use @EnableWebFlux
in a WebFluxConfigurer
class like above I posted.
That explains why the CodecCustomizer
bean had no effect. In a Boot app, the equivalent of @EnableWebFlux
will be auto-configured for you and any WebFluxConfigurer
beans will therefore be picked up automatically. Please see the relevant section of the reference documentation for a few more details.
@wilkinsona Many thanks for your explain 😀
Spring boot version: 2.4.3
I'm using webflux and upload some file, when upload file a little bit larger, spring reports:
my request http file is like:
All of those filee combine is less than 500Kb,but when I use smaller file (about 20kb total),the controller works.
my controller code(using kotlin) is like:
Another thing is I can upload files when I'm devloping on my machine,but can't upload when deploy to server,where is wrong?