title: Uploading a List of MultipartFile with Spring 4 restTemplate (Java Client & RestController)
body: <p>I am trying to post of List of MultipartFile to my RestController using spring restTemplate although I'm a bit confused as to the exact syntax &amp; types to use for my client &amp; controller. Here's what I have so far based on the research I've done...</p>
  
  <p><strong>FileUploadClient.java</strong></p>
  
  <pre><code>public void uploadFiles(List&lt;MultipartFile&gt; multiPartFileList) throws IOException {
      MultiValueMap&lt;String, Object&gt; map = new LinkedMultiValueMap&lt;&gt;();
      List&lt;Object&gt; files = new ArrayList&lt;&gt;();
      for(MultipartFile file : multiPartFileList) {
          files.add(new ByteArrayResource(file.getBytes()));
      }
      map.put("files", files);
  
      // headers is inherited from BaseClient
      headers.setContentType(MediaType.MULTIPART_FORM_DATA);
      HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; request = new HttpEntity&lt;&gt;(map, headers);
      ResponseEntity&lt;String&gt; response = restTemplate.exchange(restURI + "/rest/fileupload/uploadfiles", HttpMethod.POST, request, String.class);
      if(HttpStatus.OK.equals(response.getStatusCode())) {
          System.out.println("status for /rest/fileupload/uploadfiles ---&gt; " + response);
      }
  }
  </code></pre>
  
  <p><strong>FileUploadRestController.java</strong></p>
  
  <pre><code>@RequestMapping(value = "/uploadfiles", method = RequestMethod.POST)
  public ResponseEntity&lt;?&gt; uploadFiles(@RequestParam("files") List&lt;MultipartFile&gt; files, HttpServletRequest request) {
      ResponseEntity&lt;?&gt; response;
      try {
          // do stuff...
          response = new ResponseEntity&lt;&gt;(header, HttpStatus.OK);
          System.out.println("file uploaded");
      } catch (Exception e) {
          // handle exception
      }
      return response;
  }
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;multipartFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.multipart.support.MultipartFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;multipartFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p><strong>spring-servlet.xml</strong></p>
  
  <pre><code>&lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
      &lt;!-- max upload size in bytes --&gt;
      &lt;property name="maxUploadSize" value="20971520" /&gt; &lt;!-- 20MB --&gt;
      &lt;!-- max size of file in memory (in bytes) --&gt;
      &lt;property name="maxInMemorySize" value="1048576" /&gt; &lt;!-- 1MB --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>If I understand it correctly. The multipart filter should parse my MultiValueMap into a List of MultipartFiles and a MultipartHttpServletRequest?
  The only way I can get my client to hit my RestController is to send the file data as a ByteArrayResource, however in my Controller my RequestBody is always null and  the MultipartHttpServletRequest has an empty map for its multipartFiles attribute. I've looked at numerous posts to try to resolve this issue but to no avail. Any help would be much appreciated.</p>