title: Spring Boot + multipart/form-data controller method
body: <p>Can't seem to figure this out, no matter what I try.  I'm submitting this curl command:</p>
  
  <pre><code>curl -v -F name=countries.zip -F filedata=@countries.zip http://localhost:8080/rest
  </code></pre>
  
  <p>I have a Spring Boot 1.4 app with an annotated @RestController with the following method:</p>
  
  <pre><code>@RequestMapping(consumes = {"multipart/form-data"}, method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE}, path = {"/rest", "/rest/**"})
  public void handleMultipartRestApiRequest(MultipartHttpServletRequest request, HttpServletResponse response, @RequestPart(value = "filedata", required = false) MultipartFile filedata) throws Exception {
      r...
  }
  </code></pre>
  
  <p>The filedata variable is always null, and the request object always shows 0 files.</p>
  
  <p>I've tried multiple configurations with a MultipartResolver.  Here is my latest:</p>
  
  <pre><code>@Bean
  public MultipartResolver multipartResolver() {
      CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
      multipartResolver.setMaxUploadSize(5000000);
      multipartResolver.setMaxInMemorySize(5000000);
      multipartResolver.setDefaultEncoding("utf-8");
      return multipartResolver;
  }
  </code></pre>
  
  <p>I also manually stuck these in my application.properties just to be 1000% sure it's not disabled:</p>
  
  <pre><code>multipart.enabled=true
  </code></pre>
  
  <p>spring.http.multipart.enabled=true</p>
  
  <p>and for good measure, here are the request headers:</p>
  
  <pre><code>   * Connected to localhost (::1) port 8080 (#0)
  &gt; POST /rest HTTP/1.1
  &gt; Host: localhost:8080
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; Content-Length: 817999
  &gt; Expect: 100-continue
  &gt; Content-Type: multipart/form-data; boundary=------------------------7d3f4606455e862b
  &gt; 
  </code></pre>
  
  <p>Anybody have a clue why I can't seem to be able to see the file on my controller?</p>
  
  <p>UPDATE 1:</p>
  
  <p>If I dig far enough into the request object and get to the org.catalina.connector.Request object, there is an ArrayList of ApplicationPart items that contain a DiskFileItem that seems to hold information about the file I'm trying to upload.  This is actually the Collection that is returned when you call request.getParts().  The file item location path is some long tmp path:  </p>
  
  <pre><code>/private/var/folders/n8/15d6vbhj0692cslf3cx8c1jm0000gn/T/tomcat.6840182548028446450.8080/work/Tomcat/localhost/myapp
  </code></pre>
  
  <p>However it also says the content type is application/octet-stream, the size is -1, and some other weirdness, like "isFormField" is false even though i'm specifying it as a form field in my curl command.  So spring is calling the correct method to handle a multipart/form-data request, but yet the "part" information seems to think it's an octet-stream.  </p>