54

I am developing an application utilizing JHipster. I have added the following to my application-dev.yml file:

spring:

    profiles:
        active: dev

    multipart:
        maxFileSize: -1

But I am still getting an error when I try to try to upload a file > 1MB:

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (20663006) exceeds the configured maximum (10485760)

What am I missing? It seems this should be pretty straight forward.

Update 1

I un-nested it from spring config as suggested by Andy, but still got the error. Updated yml file:

server:
    port: 8080

multipart:
        maxFileSize: -1

spring:

    profiles:
        active: dev

    datasource: ...

Update 2

Ran into this issue again on newer version of Sprint Boot and had to change to this:

spring:
    http:
        multipart:
            max-file-size: 30MB
            max-request-size: 30MB
Jose Gulisano
  • 1,281
  • 3
  • 11
  • 12

7 Answers7

139

In addition to configuring max file size, you may also need to configure max request size if you have a single file that's greater than 10MB or you want to upload multiple files in the same request with sizes that total more than 10MB.

The exact properties that need to be used depend on the version of Spring Boot that you are using as they changed in 1.4:

Spring Boot 1.3.x and earlier

  • multipart.maxFileSize
  • multipart.maxRequestSize

Spring Boot 1.4.x and 1.5.x

  • spring.http.multipart.maxFileSize
  • spring.http.multipart.maxRequestSize

Spring Boot 2.x

  • spring.servlet.multipart.maxFileSize
  • spring.servlet.multipart.maxRequestSize
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 1
    This is the correct answer. Providing both maxFileSize and maxRequestSize will do the trick. – Turbut Alin May 09 '16 at 07:03
  • unnested it like this: multipart: maxFileSize: 100Mb maxRequestSize: 100Mb and it worked on my side :) – tibi Aug 14 '16 at 15:19
  • 4
    @christopher I've updated my answer to reflect the different properties used by different versions of Spring Boot – Andy Wilkinson Dec 29 '16 at 09:37
  • In spring boot 1.5, it changed again to be technologic specific https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Release-Notes#property-renames , for example server.tomcat.max-http-post-size – OutOfBound May 03 '17 at 08:14
  • 2
    In my case the only solution was to set `spring.servlet.multipart.maxFileSize` and `spring.servlet.multipart.maxRequestSize` properties, because configuration was done by `org.springframework.boot.autoconfigure.web.servlet.MultipartProperties` – okutane Aug 03 '17 at 12:33
  • for 2.0.0.RELEASE look to @Maksim answer – SBotirov Mar 30 '18 at 18:04
8

for spring-boot 2.x, file: src/main/resources/application.yaml

spring:
  servlet:
    multipart:
      max-file-size: -1
      max-request-size: -1
Maksim Kostromin
  • 3,273
  • 1
  • 32
  • 30
3

Like Emilio Garcia mentioned, it has to be placed under spring.http.multipart and not multipart alone. I have recently upgraded a project from Spring Boot 1.3.5 to 1.4.1 and ran into the issue that multipart.maxFileSize is no longer honored .. it appears to have changed.

Refilon
  • 3,334
  • 1
  • 27
  • 51
edgraaff
  • 481
  • 4
  • 5
2

As stated here, you need to use these properties:

spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
  • @Maksim answer is actually for current 2.0.0.RELEASE – SBotirov Mar 30 '18 at 18:03
  • Note, the unit of measurement supported are `B`, `KB`, `MB`, `GB`, and `TB`. https://docs.spring.io/spring-framework/docs/5.2.9.RELEASE/javadoc-api/org/springframework/util/unit/DataSize.html – tom_mai78101 Oct 13 '20 at 20:39
1

Grails 3’s default file size is 128000.

If You Want to increase the size go to application.yml of your project ,as i want to increase the size to 25 megabyte. the file size is set in bytes , as we see above max size is 128000 bytes. so i have to convert 25 mb into bytes.

25 mb * 1024 kb * 1024 b = 26.214.400 bytes

Now goo /grails-app/conf/application.yml

and write down these lines properly

grails: controllers: upload: maxFileSize: 26214400 maxRequestSize: 26214400

Now clean the application and run again , it will work wonders. Thanks

0

Adding below to configuration worked for me:

ribbon:
  ReadTimeout: 20000
  ConnectTimeout: 20000

Read Timeout on Request

AS Mackay
  • 2,831
  • 9
  • 19
  • 25
user2569050
  • 423
  • 6
  • 5
0

For configuring CommonsMultipartResolver with external tomcat Define a bean with bean name as MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME As the default spring boot's default MultipartFilter looks for resolver with default bean name.

@Bean(name = MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
protected MultipartResolver getMultipartResolver() {
    CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
    multipartResolver.setMaxUploadSize(20971520);//size in bytes
    multipartResolver.setMaxInMemorySize(20971520);//size in bytes
    return multipartResolver;
}