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!

Madhu Sharma
  • 562
  • 4
  • 9
Mithun Manohar
  • 85
  • 2
  • 10
  • Set max file limit according to your spring version as described here https://stackoverflow.com/a/57810158/10961238 – Romil Patel Jun 25 '20 at 04: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. – Mithun Manohar Jun 25 '20 at 06:24

1 Answers1

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
Kyun
  • 61
  • 1
  • 3
  • 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.] – Mithun Manohar Jun 25 '20 at 04:27
  • @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 – Kyun Jun 25 '20 at 11:50
  • 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. – Mithun Manohar Jun 25 '20 at 12:17