title: Spring upload file size limit error
body: <p>I am using Spring Boot and I can send images that are smaller than 1MB, but when I make a post request with a large image larger than 1MB I get this error:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>I have been looking around so many places to try to find the answer to this error. I have looked at all of these questions and tried implementing what they suggest to no avail: <a href="https://stackoverflow.com/questions/40271484/spring-upload-file-size-limit">Spring upload file size limit</a>,
  <a href="https://stackoverflow.com/questions/28572700/i-am-trying-to-set-maxfilesize-but-it-is-not-honored">I am trying to set maxFileSize but it is not honored</a>, <a href="https://stackoverflow.com/questions/26989524/org-apache-tomcat-util-http-fileupload-fileuploadbasefilesizelimitexceededexcep">org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException</a>, and <a href="https://stackoverflow.com/questions/34177873/max-limit-of-multipartfile-in-spring-boot">Max Limit of MultipartFile in spring boot</a></p>
  
  <p>I am using version 2.0.3 of Spring and here is my post mapping: </p>
  
  <pre><code>    @PostMapping("/post")
      public ResponseEntity&lt;String&gt; handleFileUpload(@RequestParam("file") MultipartFile file) {
        String message = "";
        try {
          storageService.store(file);
          files.add(file.getOriginalFilename());
  
          message = "You successfully uploaded " + file.getOriginalFilename() + "!";
          return ResponseEntity.status(HttpStatus.OK).body(message);
        } catch (Exception e) {
        message = "FAIL to upload " + file.getOriginalFilename() + "!";
        return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(message);
    }
  
  }
  </code></pre>
  
  <p>And here are all the application.properties configuration that I have tried:</p>
  
  <p>1</p>
  
  <pre><code>spring.servlet.multipart.max-file-size=-1
  spring.servlet.multipart.max-request-size=-1
  </code></pre>
  
  <p>2</p>
  
  <pre><code>spring.servlet.multipart.max-file-size=5MB
  spring.servlet.multipart.max-request-size=5MB
  </code></pre>
  
  <p>3</p>
  
  <pre><code>spring.http.multipart.max-file-size=5MB
  spring.http.multipart.max-request-size=5MB
  </code></pre>
  
  <p>4</p>
  
  <pre><code>multipart.max-file-size=5MB
  multipart.max-request-size=5MB
  </code></pre>
  
  <p>5</p>
  
  <pre><code>server.tomcat.max-file-size=5000000
  </code></pre>
  
  <p>6</p>
  
  <pre><code>server.tomcat.max-http-post-size=5000000
  </code></pre>
  
  <p>7</p>
  
  <pre><code>spring.servlet.multipart.maxFileSize=-1
  spring.servlet.multipart.maxRequestSize=-1
  </code></pre>
  
  <p>Even tried changing it to application.yml:</p>
  
  <pre><code>spring:
    servlet:
      multipart:
        max-file-size: 5MB
        max-request-size: 5MB
  </code></pre>
  
  <p>I also looked into changing the request size allowed by Tomcat in web.xml file, but I don't have a web.xml file. The Tomcat I am using is bundled in to the app. </p>