title: How to prevent file loaded in memory entirely while checking its size using CommonsMultipartFile ? (java, spring)
body: <p>I have a form object that is being filled correctly automagically by Spring. Within this form object I have a field:</p>
  
  <pre><code>CommonsMultipartFile file;
  </code></pre>
  
  <p>The user can upload a file and the form object contains the file properly. All is good. However, I want to make sure a user cannot upload files larger than 2 MB. I have made a check and also that works. </p>
  
  <p>The problem: When I upload a very large file (say 500MB), I will end up with such a large file in memory in my form object (I assume this). Is there any way to prevent this? Like, is there any way to check the file size with a validator, but without the need to load up the entire file before checking?</p>