Increase HTTP Post maxPostSize in Spring Boot
Found a solution. Add this code to the same class running SpringApplication.run.
// Set maxPostSize of embedded tomcat server to 10 megabytes (default is 2 MB, not large enough to support file uploads > 1.5 MB)
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(10000000); // 10 MB
}
);
}
};
}
Edit: Apparently adding this to your application.properties file will also increase the maxPostSize, but I haven't tried it myself so I can't confirm.
multipart.maxFileSize=10Mb # Max file size.
multipart.maxRequestSize=10Mb # Max request size.
Java Spring max. size limit for upload
So i found a working solution. I need to combine your two solutions.
Adding this to the initial class:
// Set maxPostSize of embedded tomcat server to 10 megabytes (default is 2 MB, not large enough to support file uploads > 1.5 MB)
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(100000000); // 100 MB
}
);
}
};
}
and this to the application properties:
spring.http.multipart.max-file-size=100MB
spring.http.multipart.max-request-size=100MB
Related Topics
Javafx Using Objects from Maincontroller or Other Controllers in Proper Controller Class
Differences Between "Java -Cp" and "Java -Jar"
Java: Join Array of Primitives with Separator
Java/Convert Iso-8601 (2010-12-16T13:33:50.513852Z) to Date Object
How to Create a Java 8 Localdate from a Long Epoch Time in Milliseconds
How to Insert a Character in a String at a Certain Position
Using Java Map for Range Searches
Javac Not Working in Windows Command Prompt
Running Java in Package from Command Line
Gradle to Execute Java Class (Without Modifying Build.Gradle)
Compare One String with Multiple Values in One Expression
Converting an Int to a Binary String Representation in Java
Jpanel Positions and Sizes Changes According to Screensize
How to Tell Jackson to Ignore a Property for Which I Don't Have Control Over the Source Code
How to Handle Precision Error with Float in Java
Difference Between Shutdown and Shutdownnow of Executor Service