7

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?

neptune
  • 1,211
  • 2
  • 19
  • 32

5 Answers5

7

Try this,

spring:
    servlet:
        multipart:
            max-file-size: 10MB
            max-request-size: 10MB
Parisana Ng
  • 487
  • 4
  • 14
3

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;
    }
}
David Steiman
  • 3,055
  • 2
  • 16
  • 22
3

Add this content to WebConfigurer if exist

@Bean

public MultipartConfigElement multipartConfigElement() {

     MultipartConfigFactory factory = new MultipartConfigFactory();

     factory.setMaxFileSize("100MB");

     factory.setMaxRequestSize("100MB");

     return factory.createMultipartConfig();

}
Musa
  • 2,596
  • 26
  • 25
2

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.

araknoid
  • 3,065
  • 5
  • 33
  • 35
  • I don't have `application.properties` but `application.yml`. Tried there, no effect. As I know `application-dev.yml` should override `application.yml` settings. Anyway, I have it in both, still not working. – neptune Oct 18 '17 at 14:30
  • Are you sure spring boot is picking correctly your application-dev.yml file? Are there any other yml file? – araknoid Oct 18 '17 at 15:12
  • yes, using application-dev.yml for some other settings as well without problems – neptune Oct 19 '17 at 07:37
  • 1
    `spring.http.multipart` is removed and we have to use `spring.servlet.multipart` as in https://docs.spring.io/spring-boot/docs/2.0.0.M6/reference/htmlsingle/#howto-multipart-file-upload-configuration . – Xdg May 02 '18 at 05:01
  • @Xdg You are correct, and thanks for the reminder. The question was made for SpringBoot 1.5.2. For a previous comment, I added a note at the end for the Spring Boot 2.0 changes. – araknoid May 02 '18 at 08:31
0

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.

Salim Hamidi
  • 20,731
  • 1
  • 26
  • 31