title: Spring MVC and multipart handling
body: <p>I am using Spring MVC 4, and I have a controller with the below mapping/method:</p>
  
  <pre><code>@RequestMapping(value = "/me/bio", method = RequestMethod.POST, consumes = { "multipart/form-data" })
  @ResponseBody
  public JsonResponse&lt;Boolean&gt; saveProfileBio1(Account account, @RequestPart("file") MultipartFile file, @RequestPart("profile") @Valid ProfileBio profileBio) throws ValidationException, IOException {
  ...//code here
  }
  </code></pre>
  
  <p>When I submit a multipart form data request it fails with HTTP 400 Bad request with the error " org.springframework.web.multipart.support.MissingS ervletRequestPartException: Required request part 'profile' is not present"</p>
  
  <p>Below is the raw request:</p>
  
  <pre><code>------WebKitFormBoundarynU961NKt3K534rCg
  Content-Disposition: form-data; name="profile"
  {"profileName":"Zack Smith","profileDescription":"xxx","profileWebLink" :"www.abc","profilePictureUrl":"https://s3.amazonaws.com/xxx-images/default.png","profileTitle":"CTO1"}
  ------WebKitFormBoundarynU961NKt3K534rCg
  Content-Disposition: form-data; name="file"; filename="2013-11-16 21.19.59.jpg"
  Content-Type: image/jpeg 
  </code></pre>
  
  <p>As you can see the request clearly has the "profile" part. From my debugging, the issue is that the "profile" request part does not have the "Content-type" set, and DefaultMultipartHttpServletRequest has the below method that requires it to be set and if it returns null the entire request fails with the above error.</p>
  
  <pre><code>@Override
  public HttpHeaders getMultipartHeaders(String paramOrFileName) {
  String contentType = getMultipartContentType(paramOrFileName);
  if (contentType != null) {
   HttpHeaders headers = new HttpHeaders();
   headers.add(CONTENT_TYPE, contentType);
   return headers;
  }
  else {
   return null;
  }
  }
  </code></pre>
  
  <p>Trouble is is that I can't seem to find a way to set the content-type on a FormData submit in the browser for each part and seems to be something I can't set, and Spring seems to require it.</p>
  
  <p>Any tips on how to fix this or if this is a bug?</p>
  
  <p>Thanks</p>