I\'m developing application based on Spring Boot and AngularJS using JHipster. My question is how to set max size of uploading files?
If I\'m trying
I'm using spring-boot-1.3.5.RELEASE
and I had the same issue. None of above solutions are not worked for me. But finally adding following property to application.properties
was fixed the problem.
multipart.max-file-size=10MB
put this in your application.yml
file to allow uploads of files up to 900 MB
server:
servlet:
multipart:
enabled: true
max-file-size: 900000000 #900M
max-request-size: 900000000
More specifically, in your application.yml
configuration file, add the following to the "spring:" section.
http:
multipart:
max-file-size: 512MB
max-request-size: 512MB
Whitespace is important and you cannot use tabs for indentation.
None of the configuration above worked for me with a Spring application.
Implementing this code in the main application class (the one annotated with @SpringBootApplication) did the trick.
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(10000000);//10MB
}
);
}
};
}
You can change the accepted size in the statement:
connector.setMaxPostSize(10000000);//10MB
I found the the solution at Expert Exchange, which worked fine for me.
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("124MB");
factory.setMaxRequestSize("124MB");
return factory.createMultipartConfig();
}
Ref: https://www.experts-exchange.com/questions/28990849/How-to-increase-Spring-boot-Tomcat-max-file-upload-size.html
For me nothing of previous works (maybe use application with yaml is an issue here), but get ride of that issue using that:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.util.unit.DataSize;
import javax.servlet.MultipartConfigElement;
@ServletComponentScan
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofBytes(512000000L));
factory.setMaxRequestSize(DataSize.ofBytes(512000000L));
return factory.createMultipartConfig();
}
}