title: Converting File to MultiPartFile with spring
body: <p>I want to convert File to multipartfile with spring. I have make this:</p>
  
  <pre><code>File in;
  MultipartFile file =  null;
  in = new File("C:...file on disk");
  int size = (int) in.length();
  DiskFileItem fileItem = new DiskFileItem("file", "application/vnd.ms-excel", false, nomefile, size ,in.getAbsoluteFile());
  file = new CommonsMultipartFile(fileItem);
  </code></pre>
  
  <p>but receive this exception: </p>
  
  <pre><code>threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  java.lang.NullPointerException
      at org.apache.commons.fileupload.disk.DiskFileItem.getSize(DiskFileItem.java:316)
  </code></pre>
  
  <p>i think that fileItem is null but on debug mode is populated, there is another solution?
  I have this post <a href="https://stackoverflow.com/questions/16648549/converting-file-to-multipartfile">Converting File to MultiPartFile</a> but not work and not have solution.</p>