Reputation: 1261
Using Jhipster with Spring+Mongo and Gridfs to handle files saved in db. When I'm trying to upload files larger than 1Mb it gives me an 500 error:
java.io.IOException: UT000054: The maximum size 1048576 for an individual file in a multipart request was exceeded
Tried to set this in application-dev.yml without success:
spring:
http:
multipart:
max-file-size: 10MB
max-request-size: 10MB
How could this limit be changed?
Upvotes: 7
Views: 7380
Reputation: 21391
For spring boot2.x:
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
and for older version
spring:
http:
multipart:
max-file-size: 10MB
max-request-size: 10MB
For unlimited upload file size, set setting max-file-size: -1 will make it for infinite file size.
Upvotes: 0
Reputation: 2662
Add this content to WebConfigurer if exist
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("100MB");
factory.setMaxRequestSize("100MB");
return factory.createMultipartConfig();
}
Upvotes: 3
Reputation: 3125
Instead of configuring it in your application-dev.yml
, you can configure these 2 properties in your application.properties
file:
spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB
For additional information, you can give a check to Spring Uploading file guide.
As a side note, if you decide later on to migrate to spring-boot 2.0, these properties have changed from spring.http.multipart
to spring.servlet.multipart
.
Upvotes: 2
Reputation: 517
Try this,
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
Upvotes: 7
Reputation: 3145
as JHipster uses undertow, a way of fixing this is setting the upload size in a multipart resolver bean like this:
@Configuration
public class UndertowConfiguration {
@Value("${spring.http.multipart.max-file-size:10}")
private long maxFileSize;
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setDefaultEncoding("utf-8");
multipartResolver.setResolveLazily(true);
multipartResolver.setMaxUploadSize(1024*1024*maxFileSize);
multipartResolver.setMaxUploadSizePerFile(1024*1024*maxFileSize);
return multipartResolver;
}
}
Upvotes: 3