title: Conversion between org.springframework.web.multipart.MultipartFile and org.springframework.core.io.Resource
body: <p>I am trying to pass a resource as a @RequestPart to my controller. </p>
  
  <pre><code>@RequestPart(name = "resource", required = false) Resource multipartFile,
  </code></pre>
  
  <p>It seem to work good in my integration tests where I pass it as a Resource:</p>
  
  <pre><code>ByteArrayResource resource = new ByteArrayResource(new byte[] {65, 66, 67});    
  MultipartBodyBuilder b = new  MultipartBodyBuilder();
  b.part("resource", resource, MediaType.APPLICATION_PDF);
  return webClient.post().uri(getUri()
                         .contentType(MediaType.MULTIPART_FORM_DATA)
                         .syncBody(b.build())
                         .retrieve()
                         .bodyToMono(Long.class);
  </code></pre>
  
  <p>However in unit tests, I always receive resource = null. I use MockMVC for that:</p>
  
  <pre><code>MvcResult result = mvc.perform(
              multipart(getUri())
                  .file("resource", new byte[] {65, 66, 67})
                  .content(new byte[] {65, 66, 67})
                  .accept(MediaType.MULTIPART_FORM_DATA)
              .andExpect(status().isOk())
              .andReturn();
  </code></pre>
  
  <p>On the other hand, if I switch to using MultipartFile as parameter type in my Controller:</p>
  
  <pre><code>@RequestPart(name = "resource", required = false) MultipartFile multipartFile
  </code></pre>
  
  <p>It works if I pass a <code>MockMultipartFile</code> in unit tests, but I don't know how to pass a <code>MultipartFile</code> in my integration tests (and in the other service that uses my api). I tried implementing <code>org.springframework.web.multipart.MultipartFile</code> by wrapping over my <code>ByteArrayResource</code>, but it doesn't look right (and doesn't work). I've spent way too much time on this already... Any recommendations?</p>
  
  <p>P.S. I use StandardServletMultipartResolver </p>