title: Spring MVC file upload via MultipartFile gives sometimes(!) empty InputSteam
body: <p>we encountered a strange problem with our simple file upload system.</p>
  
  <p>The setup is: Spring 3.2.2, commons fileupload 1.3, commons io 2.4. We're actually running straight from Eclipse with an external Tomcat 7.0.40. It's been tested on Mac OS X 10.8 and 10.6.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>public void saveFile(MultipartFile file, String description) {
      System.out.println(file.getOriginalFilename());
      System.out.println(file.getSize());
      OutputStream out = new FileOutputStream("someFileName");
      IOUtils.copy(file.getInputStream(), out);
      out.flush();
      out.close();
  }
  </code></pre>
  
  <p>It outputs the correct file name <em>and also the correct file size</em>!</p>
  
  <p>Now when it comes to writing the file to disk, it produces a 0 byte file. This especially happens with <code>.docx</code> files (in about 95% of the cases). It seems to depend on the file. Images and PDF documents seem to work always.</p>
  
  <p>There's no exception or any other hint. <strong>The debugger says that the <code>InputStream</code> is empty (not <code>null</code>, just empty).</strong></p>
  
  <p>Any explanation for this behaviour? </p>