title: Spring-boot MultipartFile issue with ByteArrayResource
body: <p>I'm trying to implement a rest api consuming excel file. I'm using spring-boot and code is available <a href="https://github.com/ikane/demo-restapi-multipartfile" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Code works fine when using <strong>FileSystemResource</strong> for payload. But i'm not able to make the code work with ByteArrayResource in replacement of <strong>FileSystemResource</strong>:</p>
  
  <p><strong>RestApi.java:</strong></p>
  
  <pre><code>@RestController
  public class RestApi {
      private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  
      @PostMapping("/api/upload")
      public ResponseEntity&lt;?&gt; uploadFile(@RequestParam("file") MultipartFile uploadfile) {
          LOGGER.debug("Single file upload!");
          try {
              LOGGER.info("\n\n ****** File name: {}, type {}! ************", uploadfile.getOriginalFilename(), uploadfile.getContentType());
              this.processExcelFile(uploadfile.getInputStream());
          } catch (Exception e) {
              return new ResponseEntity&lt;&gt;(HttpStatus.BAD_REQUEST);
          }
          return new ResponseEntity&lt;&gt;("Successfully uploaded - " + uploadfile.getOriginalFilename(), new HttpHeaders(), HttpStatus.OK);
      }
  
      private List&lt;String&gt; processExcelFile(InputStream stream) throws Exception {
          List&lt;String&gt; result = new ArrayList&lt;String&gt;();      
  
           //Create Workbook instance holding reference to .xlsx file
           try(XSSFWorkbook workbook = new XSSFWorkbook(stream);) {
               //Get first/desired sheet from the workbook
               XSSFSheet sheet = workbook.getSheetAt(0);
               //Iterate through each rows one by one
               Iterator&lt;Row&gt; rowIterator = sheet.iterator();
               while (rowIterator.hasNext()) {
                   Row row = rowIterator.next();
                   String cellValue = row.getCell(0).getRichStringCellValue().toString();
                   result.add(cellValue);
                   LOGGER.info("\n\n ****** Cell value: {} ************", cellValue);
               }
              return result;
           }
      }
  }
  </code></pre>
  
  <p><strong>RestApiTest:</strong></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
  public class RestApiTest {
  
      @Autowired
      private TestRestTemplate restTemplate;
  
      @Autowired
      private ResourceLoader loader;
  
      @Test
      public void testUploadFile() throws Exception {
  
          Resource resource = this.loader.getResource("classpath:test.xlsx");
  
          MultiValueMap&lt;String, Object&gt; parts = new LinkedMultiValueMap&lt;&gt;();           
  //      parts.add("file", new FileSystemResource(resource.getFile()));
          parts.add("file", new ByteArrayResource(IOUtils.toByteArray(resource.getInputStream())));
  
          String response = this.restTemplate.postForObject("/api/upload", parts, String.class);
  
          Assertions.assertThat(response).containsIgnoringCase("success");
      }
  }
  </code></pre>
  
  <p>I'm getting following error when running test:</p>
  
  <pre><code>java.lang.AssertionError: 
  Expecting:
   &lt;"{"timestamp":1487852597527,"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'file' is not present","path":"/api/upload"}"&gt;
  to contain:
   &lt;"success"&gt;
   (ignoring case)
  </code></pre>
  
  <p>Any idea?</p>