title: Spring MVC multiple file upload with HTML5 multiple file form feature
body: <p>I am trying to upload multiple files using spring 3.1.2 with @Controller and @RequestMapping.</p>
  
  <p>Here's  what I did and my configuration.</p>
  
  <p>Html5 form : </p>
  
  <pre><code>&lt;form action="addFileSystemImage.foo" method="post" enctype="multipart/form-data"&gt;
  
      &lt;input class='fileInput' type="file" name="files[]" multiple="multiple" /&gt;
  
      &lt;input type="text" value="13asdf12eadsf" name="locId"/&gt;
  
      &lt;input type="submit" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Controller method :</p>
  
  <pre><code>@RequestMapping(value="/publisher/addFileSystemImage.foo", method=RequestMethod.POST)
  public @ResponseBody List&lt;UploadedFile&gt; addFileSystemImage(@RequestParam("files[]") ArrayList&lt;MultipartFile&gt; files, String locId, HttpServletRequest request) {
  
   //do lotsa voodoo rocket science here to process the files  
  
  }
  </code></pre>
  
  <p>my conf : </p>
  
  <pre><code> &lt;mvc:annotation-driven /&gt;
   &lt;context:component-scan base-package="foo.package"&gt;&lt;/context:component-scan&gt;
   &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;&lt;/bean&gt;
  </code></pre>
  
  <p>Submitting the form does get to the addFileSystemImage method. The data for locId argument is here, but the "files" argument is not bound. It is systematically null no matter what combination of argument / field names / argument types I have tried.</p>
  
  <p>The HttpServletRequest argument is a org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest and it holds a multiPartFile attribute which actually holds the file data. Looking at its value in debug gives me </p>
  
  <pre><code>{files[]=[org.springframework.web.multipart.commons.CommonsMultipartFile@16afd7f9, org.springframework.web.multipart.commons.CommonsMultipartFile@728c2811, org.springframework.web.multipart.commons.CommonsMultipartFile@4f9aaed7]}
  </code></pre>
  
  <p>which means my files[] is indeed here ... but somehow it did not pass the data binding step properly ... </p>
  
  <p>Now ... I know you're gonna tell me I can retrieve the data from the request ... but I'd rather have this working properly ... the Sring way... :) and have my ArrayList of MultipartFile properly populated. </p>
  
  <p>Am I missing something ? Has anyone actually made this work properly ? What can I do to have this ArrayList (or even an regular Array ) populated? </p>
  
  <p>I came accross this solution 
  <a href="https://stackoverflow.com/questions/7246041/spring-mvc-with-ajax-file-upload-and-multipartfile/11329508#11329508">Spring MVC with ajax file upload and MultipartFile</a> which does pretty much the same thing as I am but obviously I must be  doing something wrong since this solution is not working for me.</p>
  
  <p>Note : I did manage to get it working with single file uploads. But my challenge today is to get multiple files at once. </p>
  
  <p>Any help appreciated. </p>
  
  <p>Thanks in advance.</p>