upload file size limit in spring boot
Asked Answered
S

4

11

In version 2.1.0, spring.servlet.multipart.max-file-size property failed to bind org.springframework.util.unit.DataSize.

Property : spring.servlet.multipart.maxFileSize= 50Mb

Exception

Description:

Failed to bind properties under 'spring.servlet.multipart.max-file-size' to org.springframework.util.unit.DataSize:

Property: spring.servlet.multipart.maxfilesize
Value: 50Mb
Origin: "spring.servlet.multipart.maxFileSize" from property source "bootstrapProperties"
Reason: failed to convert java.lang.String to @org.springframework.boot.convert.DataSizeUnit org.springframework.util.unit.DataSize

Action:

Update your application's configuration
Shlomo answered 7/11, 2018 at 11:18 Comment(2)
MB with a capital 'B'.Ichnology
github.com/spring-projects/spring-framework/blob/master/… here you can see that "B" is indeed capitalVotyak
S
19

As Michael & Stahorszki mentioned

"B"

must be capital

Property : spring.servlet.multipart.maxFileSize= 50MB

In Yaml

spring:    
  servlet:
    multipart:
      max-file-size: ${MAX_FILE_SIZE:8MB}
      max-request-size: ${MAX_REQUEST_SIZE:8MB}
Shlomo answered 7/11, 2018 at 12:46 Comment(1)
Mine had \r at the and Using export I was getting the same Error.Semipalatinsk
F
0

Today I have repeated this error, althought I set "MB" with capital "B":

Description:

Failed to bind properties under 'spring.servlet.multipart.max-file-size' to org.springframework.util.unit.DataSize:

    Property: spring.servlet.multipart.max-file-size
    Value: 300MB 
    Origin: class path resource [application.properties]:27:40
    Reason: failed to convert java.lang.String to org.springframework.util.unit.DataSize

If I comment out this options application wouldn't start anyway - there are some errors in the spring context. So I think it is a wrong error message then context cannot be created + multipart options are given.

Frankel answered 30/7, 2019 at 11:12 Comment(1)
I had a space AFTER 300MB and it was causing it to fail. Would be nice if binding would remove white spaces automatically and ignore the case comparison on mb or kb.....Texas
I
0

In my case, I had redundant whitespace at the end of size (after MB, KB). To fix this, I deleted the space.

Iggie answered 3/4, 2022 at 9:15 Comment(0)
S
0

Remove the space as well after 50MB, I faced the same error but due to space after value attribute

enter image description here

Status answered 1/10, 2023 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.