commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1455085 - /commons/proper/fileupload/trunk/src/site/fml/faq.fml
Date Mon, 11 Mar 2013 10:32:33 GMT
Author: simonetripodi
Date: Mon Mar 11 10:32:32 2013
New Revision: 1455085

URL: http://svn.apache.org/r1455085
Log:
[FILEUPLOAD-143] #comment somehow Jochen's entry was not previously included in the FAQ, this
commit to restore the workaround for Flash client having the `Stream ended unexpectedly` issue
#resolve

Modified:
    commons/proper/fileupload/trunk/src/site/fml/faq.fml

Modified: commons/proper/fileupload/trunk/src/site/fml/faq.fml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/site/fml/faq.fml?rev=1455085&r1=1455084&r2=1455085&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/site/fml/faq.fml (original)
+++ commons/proper/fileupload/trunk/src/site/fml/faq.fml Mon Mar 11 10:32:32 2013
@@ -122,4 +122,56 @@
     </faq>
   </part>
 
+  <part id="flash">
+    <title>FileUpload and Flash</title>
+
+    <faq id="missing-boundary-terminator">
+      <question>
+        I'm using FileUpload to receive an upload from flash, but
+        FileUpload will always throw an Exception "Stream ended unexpectedly".
+        What can I do?
+      </question>
+      <answer>
+        <p>
+          At least as of version 8, Flash contains a known bug: The multipart
+          stream it produces is broken, because the final boundary doesn't
+          contain the suffix "--", which ought to indicate, that no more
+          items are following. Consequently, FileUpload waits for the next
+          item (which it doesn't get) and throws an exception.
+        </p>
+        <p>
+          The problems details and a possible workaround are outlined in
+          <a href="http://issues.apache.org/jira/browse/FILEUPLOAD-143">
+            Bug 143
+          </a>
+          . The workaround suggests to use the streaming API
+          and catch the exception. The resulting code could look like
+          this:
+        </p>
+        <pre><![CDATA[final List<FileItem> items = new ArrayList<FileItem>();
+
+HttpServletRequest servletRequest = [...];
+RequestContext ctx = new ServletRequestContext(servletRequest);
+
+FileItemFactory fileItemFactory = new DiskFileItemFactory();
+
+ServletFileUpload upload = new ServletFileUpload();
+FileItemIterator iter = upload.getItemIterator(ctx);
+try {
+    while (iter.hasNext()) {
+        FileItemStream item = iter.next();
+        FileItem fileItem = fileItemFactory.createItem(item.getFieldName(),
+                                                       item.getContentType(),
+                                                       item.isFormField(),
+                                                       item.getName());
+        Streams.copy(item.openStream(), fileItem.getOutputStream(), true);
+        items.add(fileItem);
+    }
+} catch (MalformedStreamException e) {
+    // Ignore this
+}]]></pre>
+      </answer>
+    </faq>
+  </part>
+
 </faqs>



Mime
View raw message