title: Spring MultipartFile parameter not respecting configured maxFileSize
body: <p>I have a file upload Controller. I'm trying to make the max file size configurable, but I'm not able to figure out why the configuration as documented (<a href="https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-multipart-file-upload-configuration" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-multipart-file-upload-configuration</a>) is not being applied.</p>
  
  <pre><code>plugins {
      id 'org.springframework.boot' version '2.1.4.RELEASE'
      id 'java'
  }
  
  apply plugin: 'io.spring.dependency-management'
  
  group = 'com.example'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = '1.8'
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation 'org.springframework.boot:spring-boot-starter-web'
      testImplementation 'org.springframework.boot:spring-boot-starter-test'
  }
  
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.multipart.MultipartFile;
  
  import javax.servlet.MultipartConfigElement;
  import java.io.BufferedInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  
  @Controller
  public class FileUploadController {
  
    private MultipartConfigElement multipartConfigElement;
  
    @Autowired
    public FileUploadController(MultipartConfigElement multipartConfigElement) {
      this.multipartConfigElement = multipartConfigElement;
    }
  
    @PostMapping("/upload")
    public void upload(@RequestParam("file") MultipartFile file) throws IOException {
      InputStream inputStream = new BufferedInputStream(file.getInputStream());
      // TODO something with inputStream
  
      long fileSize = file.getSize();
      boolean fileSizeLimitExceeded = fileSize &gt; multipartConfigElement.getMaxFileSize();
      return;
    }
  }
  
  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1looJ.png" rel="nofollow noreferrer">Debug screenshot</a></p>
  
  <p>I expect the multipartConfigElement.getMaxFileSize() should prevent larger files getting this far and automatically return a 400 or some other type of exception.</p>
  
  <p>But instead the maxFileSize seems to be completely ignored.</p>