Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am trying to set maxFileSize but it is not honored

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
like image 811
Jose Gulisano Avatar asked Feb 17 '15 22:02

Jose Gulisano


4 Answers

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
like image 81
Andy Wilkinson Avatar answered Dec 08 '22 23:12

Andy Wilkinson


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

spring:
  servlet:
    multipart:
      max-file-size: -1
      max-request-size: -1
like image 22
Maksim Kostromin Avatar answered Dec 09 '22 01:12

Maksim Kostromin


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.

like image 37
edgraaff Avatar answered Dec 09 '22 01:12

edgraaff


As stated here, you need to use these properties:

spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
like image 20
Emilio Garcia Avatar answered Dec 08 '22 23:12

Emilio Garcia