0
votes

Spring boot application. I have a rest endpoint for uploading a multipart file.

 Controller.java
 @PostMapping(value = "/upload", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public ResponseEntity uploadFile(
            @RequestParam("file") MultipartFile file, @RequestParam("folder") String folder) {
        tests.uploadFile(file, folder);
        return new ResponseEntity(HttpStatus.OK);
 }

Getting the following exception while uploading 5MB file in POSTMAN. enter image description here

Spring boot version is 2.0.6. I have tried the following methods.

1)spring: tomcat: max-http-form-post-size: 500MB max-swallow-size: 500MB

2)spring: servlet: multipart: max-file-size: 500MB max-request-size: 500MB enabled: true

3)spring: servlet: multipart: max-file-size: -1 max-request-size: -1 enabled: true

Still i am getting this same exception. When i try to upload a small file of size less than 1 mb i am able to process it, but when i try to upload a file of size 5mb or greater i am not able to debug or process it.

Can someone help me on this . Thanks in advance!

1
Set max file limit according to your spring version as described here stackoverflow.com/a/57810158/10961238 - Romil Patel
Added still getting this exception java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes. - Mithun Manohar

1 Answers

1
votes

It works in my application , only has these simple configurations in application.yml

spring:
  servlet:
    multipart:
      max-file-size: 500MB
      max-request-size: 500MB