title: @RequestPart with mixed multipart request, Spring MVC 3.2
body: <p>I'm developing a RESTful service based on Spring 3.2. I'm facing a problem with a controller handling mixed multipart HTTP request, with a Second part with XMLor JSON formatted data and a second part with a Image file . </p>
  
  <p>I am using <a href="http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/new-in-3.1.html#new-in-3.1-mvc-requestpart">@RequestPart annotation </a> for receiving the request</p>
  
  <pre><code>@RequestMapping(value = "/User/Image", method = RequestMethod.POST,  consumes = {"multipart/mixed"},produces="applcation/json")
  
  public
  ResponseEntity&lt;List&lt;Map&lt;String, String&gt;&gt;&gt; createUser(
          @RequestPart("file") MultipartFile file, @RequestPart(required=false) User user) {
  
      System.out.println("file" + file);
  
      System.out.println("user " + user);
  
      System.out.println("received file with original filename: "
              + file.getOriginalFilename());
  
      // List&lt;MultipartFile&gt; files = uploadForm.getFiles();
      List&lt;Map&lt;String, String&gt;&gt; response = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
      Map&lt;String, String&gt; responseMap = new HashMap&lt;String, String&gt;();
  
      List&lt;String&gt; fileNames = new ArrayList&lt;String&gt;();
  
      if (null != file) {
          // for (MultipartFile multipartFile : files) {
  
          String fileName = file.getOriginalFilename();
          fileNames.add(fileName);
  
          try {
              file.transferTo(new File("C:/" + file.getOriginalFilename()));
          } catch (IllegalStateException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      responseMap.put("displayText", file.getOriginalFilename());
      responseMap.put("fileSize", "" + file.getSize());
      response.add(responseMap);
  
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.add("Accept", "application/json");
      return new ResponseEntity&lt;List&lt;Map&lt;String, String&gt;&gt;&gt;(response,
              httpHeaders, HttpStatus.OK);
  
  }
  </code></pre>
  
  <p>User.java will be like this- </p>
  
  <pre><code>@XmlRootElement(name = "User")
  
  
  public class User implements Serializable { 
      private static final long serialVersionUID = 1L;
  
      private int userId;
      private String name;
      private String email;
  
      private String company;
      private String gender;
  
      //getter setter of the data members
  }
  </code></pre>
  
  <p>To my understanding, using the @RequestPart annotation I would expect the XML multipart section to be evaluated depending on its Content-Type and finally un-marshalled into my User class (I'm using Jaxb2, the marshaller/unmarhaller is properly configured in the application context and the procedure is working fine for all the other controller methods when I pass the XML data as body and use the @RequestBody annotation). </p>
  
  <p>But what is actually happening is that, although the file is correctly found and parsed as MultipartFile, the "user" part is never seen and the request is always failing, not matching the controller method signature. </p>
  
  <p>I reproduced the problem with several clients type and I am confident the format of the multipart request is ok. </p>
  
  <p>Please help me to solve this issue, Maybe some workaround will be there to receive mixed/multipart request. </p>
  
  <p>Thanks and Regards, </p>
  
  <p>Raghvendra </p>