简体   繁体   中英

Spring boot file multipart accept half allowed size

I wrote a controller as below:

@PostMapping(value="/upload", produces = "application/json")
@ApiOperation("Upload")
@ApiIgnore
public ResponseEntity<ResponseObject> fileUpload(
        @RequestParam(value="file") MultipartFile file,
        @RequestParam (value="code",required=false, defaultValue="0")String code,
        @RequestParam (value="approvaldetails",required=false, defaultValue="0") String approvalDeatils) throws Exception{
    return uploadService.uploader(file,code,approvalDeatils);
}

and I configured below at application.porperties:

spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=30MB

but I could able to upload file up to ~15MB Editted: Spring boot version: 2.0.1

1. First potential cause:

Maybe it's related to the spring-boot version you are using.

MULTIPART properties have been changed according to versions.

Spring Boot 1.3.x and earlier

multipart.max-file-size
multipart.max-request-size

After Spring Boot 1.3.x:

spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1

After Spring Boot 2.0:

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1 

2. Second potential cause:

Your app didn't have enough memory to receive the file

3. Third potential cause:

If you are packaging as war and deploying on tomcat, make sure that tomcat allows a maxPostSize suitable for your use case.

In conf\\server.xml:

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
                maxPostSize="67589953" />

@M.Mas. 1.I'm using spring boot 2.0.1. 2.Not depends on memory even if I decrease to 8MB, again ~4MB will be acceptable. 3. It is not deployed on the WAR file and I'm debugging. I uploaded a file with 16.8MB and it raised below exception:

org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size ( 33542171 ) exceeds the configured maximum (31457280)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM