title: issues with form/iframe based file upload in Opera
body: <h2>SOLUTION</h2>
  
  <p>Refer to my answer below: <a href="https://stackoverflow.com/questions/7899327/issues-with-form-iframe-based-file-upload-in-opera/7936689#7936689">issues with form/iframe based file upload in Opera</a></p>
  
  <hr>
  
  <p>I'm using the form/iframe technique to send files to the server whenever a browser does not support XMLHttpRequest upload (Opera). On a high level, here's the setup...</p>
  
  <ol>
  <li>create an iframe <code>&lt;iframe src="javascript:false;" name="file-iframe"&gt;&lt;/iframe&gt;</code></li>
  <li>create a form <code>&lt;form enctype="multipart/form-data" method="POST"&gt;</code>
  
  <ul>
  <li>set target = iframe's name, <code>target="file-iframe"</code></li>
  <li>set action = url, <code>action="/upload"</code></li>
  </ul></li>
  <li>add the file input to the form</li>
  <li>submit form</li>
  </ol>
  
  <p>When the form is submitted, the server spits out an exception:</p>
  
  <pre><code>org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
      at org.apache.commons.fileupload.MultipartStream.readHeaders(MultipartStream.java:538)
      at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:999)
      at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.&lt;init&gt;(FileUploadBase.java:965)
      at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
      at org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(ServletFileUpload.java:148)
      at com.beamit.jetty.UploadServlet.doPost(UploadServlet.java:28)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      ...
      ...
  </code></pre>
  
  <p>Here is a code snippet in the <code>UploadServlet.java</code> file, where the failure happens in the last line of the snippet:</p>
  
  <pre><code>@Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) {
  
      ServletFileUpload up = new ServletFileUpload();
      try {
          FileItemIterator iter = up.getItemIterator(request); // &lt;------ ERROR
          ...
      } catch (IOException e) {
          e.printStackTrace();
      }
      ...
  </code></pre>
  
  <p>I've been trying to debug this for hours and I'm getting nowhere. Any ideas as to why this might be happening? </p>
  
  <p>I can provide the HTTP requests for working/non-working file uploads using a different browser, as well as some more source code if needed.</p>
  
  <h2>MORE INFO</h2>
  
  <p>HTTP request for a simple "hello world" text file in <strong>Chrome</strong>.</p>
  
  <pre><code>POST /upload/0145c HTTP/1.1
  Host: beamit:8080
  Connection: keep-alive
  Cache-Control: max-age=0
  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Referer: http://beamit:8080/
  Content-Length: 44
  Origin: http://beamit:8080
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryQes3eWoFE2iw6kGE
  </code></pre>
  
  <p>HTTP request for a simple "hello world" text file in <strong>Opera</strong>.</p>
  
  <pre><code>POST /upload/f889b HTTP/1.1
  User-Agent: Opera/9.80 (Macintosh; Intel Mac OS X 10.7.2; U; en) Presto/2.9.168 Version/11.52
  Host: beamit:8080
  Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
  Accept-Language: en,en-US;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1,sv;q=0.1,nb;q=0.1,da;q=0.1,fi;q=0.1,ru;q=0.1,pl;q=0.1,zh-CN;q=0.1,zh-TW;q=0.1,ko;q=0.1,ar;q=0.1,cs;q=0.1,hu;q=0.1,tr;q=0.1
  Accept-Encoding: gzip, deflate
  Referer: http://beamit:8080/
  Cookie: __utma=248039316.1622718495.1317335167.1319648741.1319655028.19; __utmb=248039316.4.10.1319655028; __utmc=248039316; __utmz=248039316.1317335167.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
  Connection: Keep-Alive
  Content-Length: 76
  Content-Type: multipart/form-data; boundary=----------cah2BDOhbumylzxVY398ZJ
  </code></pre>