0

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!

2
  • Set max file limit according to your spring version as described here stackoverflow.com/a/57810158/10961238 Commented Jun 25, 2020 at 4:50
  • 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. Commented Jun 25, 2020 at 6:24

1 Answer 1

2

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

spring:
  servlet:
    multipart:
      max-file-size: 500MB
      max-request-size: 500MB
Sign up to request clarification or add additional context in comments.

3 Comments

I added these configurations and checked in my application. Still i m getting the same exception. Why is that ? threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.]
@MithunManohar Is there any other configurations in your application.yml/application.properties or any other dependencies in your project ? My testing application is just a simple project that only contains "spring-boot-starter-web" module.spring boot version 2.0.6.RELEASE
The issue is resolved the problem was with my application.yml file I was adding these configurations just below the three dashes that is why it was not working for me. Actually it has to be above those three dashes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.