title: Reading MultiPart content in Java Servlet
body: <p>ServletRequest has an API getParts() for reading the parts of a multi part request
  <a href="https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getParts()" rel="nofollow noreferrer">https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getParts()</a></p>
  
  <p>It has part.getInputStream which can be used to read the content of a specific part.</p>
  
  <p>For this to work servlet has to be annotated with <a href="https://docs.oracle.com/javaee/6/api/javax/servlet/annotation/MultipartConfig.html" rel="nofollow noreferrer">https://docs.oracle.com/javaee/6/api/javax/servlet/annotation/MultipartConfig.html</a></p>
  
  <p>MultiPartConfig has an element for location which i think writes the parts to disk if required. This means the part content is loaded into memory first internally and then after reaching the threshold the part contents are written to disk</p>
  
  <p>Why does the getPart API needs to load the content in memory ? Why can't direct streaming of content happen ? Loading the content in memory and reading/writing to disk brings extra cost. This will be specially costly when large files are geing uploaded.</p>
  
  <p>Is there no way where at least the file content loading could be avoided ?</p>
  
  <p>Best Regards,</p>
  
  <p>Saurav</p>