title: Uploading files to server via JSF 2.2 and h:inputFile
body: <p>UPDATE:<br>
  It turns out that there was an ajax call inside the inputFile that would cause the upload to start prematurely. That ajax was supposed to handle the selected file before the actual submit button was clicked, but neither I nor the person who coded it before me knew it would behave that way. And, as we only tested it either locally or with small files, we never noticed the problem.</p>
  
  <hr>
  
  <p>I'm a newbie when it comes to file upload and I need some guidance on that subject.<br>
  I have a code that gets a file through h:inputFile then, when the submit button is pressed, sends it to the server using InputStream and OutputStream in a pretty standard way. It works well, but I'm facing a problem:</p>
  
  <p>When I select the file, it takes its time to upload to the page(?). Then, when I click the submit button, it takes its time again to send that file to the server.<br>
  To make myself clear, here's a real case: I clicked the inputFile button and selected a 50mb file. It took 10min to conclude that. Then, I clicked the submit button and it took another 10min to send it to the server. That's a total 20min to upload that file, when it should have been only 10min.</p>
  
  <p>Saving that time is crucial for my users, since their internet is very slow (&lt; 1mbps) and they will be uploading videos around 40-90mb, which will take hours.<br>
  So, how do I optimize that? And, as I'm already asking, how exactly does h:inputFile work - I mean, it sets the Part in the bean, which can then be handled, but does it actually upload the file right away?</p>
  
  <p>I'm using JSF 2.2.7 and GlassFish 4.<br>
  (Sorry that I didn't post the code, but I don't really think it's necessary. If that's not the case, just let me know.)</p>