Reputation: 630
I'm getting error while uploading excel file size is more the 1MB.
[org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException:
The field files exceeds its maximum permitted size of 1048576 bytes.]
I tried to fix it by applying the following config changes but none of them help me.
Try with configuration in application.yml
file :
spring:
http:
multipart:
max-file-size:5MB
max-request-size:5MB
And also I've tried the below annotation:
@MultipartConfig(fileSizeThreshold=1024*1024*10,maxFileSize=1024*1024*10,maxRequestSize=1024*1024*10)
And last I made this change:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" maxSwallowSize="-1" />
But nothing does work !
Upvotes: 5
Views: 11254
Reputation: 301
For Spring boot 2.x and above its
Application properties
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
YAML
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
Upvotes: 0
Reputation: 15878
There is a typo in your property S
in Spring is uppercase instead of lowercase.
With spring-boot 1.5.2 you can use the following property in application.yml
spring:
http:
multipart:
max-file-size: 100MB
max-request-size: 100MB
Make sure to use spaces and not tab in your yaml file.
Upvotes: 2
Reputation: 21
Try using the below code:
spring:
profiles: development
servlet:
multipart:
enabled: true
max-file-size: 10MB
max-request-size: 10MB
Upvotes: 2
Reputation: 550
I tried Alien's solution but it gave deprecated error, hence I want to share new way of solution
spring.servlet.multipart.max-request-size=10MB
spring.servlet.multipart.max-file-size=10MB
Upvotes: 8
Reputation: 83
Include below code in your SpringBootWebApplication class(Main):
For Java 8:
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 for unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return tomcat;
}
for Java 7:
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
//-1 for unlimited
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
}
});
return tomcat;
}
Upvotes: 0