[
https://issues.apache.org/jira/browse/FILEUPLOAD-143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12892380#action_12892380
]
Luke Scott edited comment on FILEUPLOAD-143 at 7/26/10 1:34 PM:
----------------------------------------------------------------
It's been quite a long time since I posted this issue... So I don't remember
the specifics. It is indeed a problem with Flash and how it uploads files. I
ended up using a servlet with the streaming API. Below is a block of code from
my class. Much of it is stripped down to include the important stuff. It won't
work as-is, but hopefully will be of some help:
{code}
public class UploadServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String[] session = request.getParameterValues("s");
Boolean isMultipart =
ServletFileUpload.isMultipartContent(request);
if( request.getContentLength() > 0 && isMultipart && session !=
null && session.length > 0 )
{
try
{
ServletFileUpload upload = new
ServletFileUpload();
FileItemIterator iter =
upload.getItemIterator(request);
while( iter.hasNext() )
{
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if( !item.isFormField() &&
item.getFieldName().equals("Filedata") )
{
String filename =
Long.toString(System.currentTimeMillis(), 36);
String tmpPath = "." + filename
+ ".tmp";
String finPath = filename;
OutputStream outstream = new
FileOutputStream( tmpPath );
Streams.copy(stream,outstream,true);
stream.close();
outstream.close();
File tmpFile = new File(
tmpPath );
File finFile = new File(
finPath );
tmpFile.renameTo( finFile );
}
}
}
catch( Exception e ) { }
}
}
}
{code}
was (Author: lukescott):
It's been quite a long time since I posted this issue... So I don't
remember the specifics. It is indeed a problem with Flash and how it uploads
files. I ended up using a servlet with the streaming API. Below is a block of
code from my class. Much of it is stripped down to include the important stuff.
It won't work as-is, but hopefully will be of some help:
{code}
public class UploadServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String[] session = request.getParameterValues("s");
Boolean isMultipart =
ServletFileUpload.isMultipartContent(request);
if( request.getContentLength() > 0 && isMultipart && session !=
null && session.length > 0 )
{
try
{
ServletFileUpload upload = new
ServletFileUpload();
FileItemIterator iter =
upload.getItemIterator(request);
while( iter.hasNext() )
{
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if( !item.isFormField() &&
item.getFieldName().equals("Filedata") )
{
String filename =
Long.toString(System.currentTimeMillis(), 36);
String tmpPath = "." + filename
+ ".tmp";
String finPath = filename;
OutputStream outstream = new
FileOutputStream( tmpPath );
Streams.copy(stream,outstream,true);
stream.close();
outstream.close();
File tmpFile = new File(
tmpPath );
File finFile = new File(
finPath );
tmpFile.renameTo( finFile );
}
}
}
catch( Exception e ) { }
}
}
}
{/code}
> "Stream ended unexpectedly"
> ---------------------------
>
> Key: FILEUPLOAD-143
> URL: https://issues.apache.org/jira/browse/FILEUPLOAD-143
> Project: Commons FileUpload
> Issue Type: Bug
> Affects Versions: 1.2
> Environment: CentOS 4.4, Jetty running through Red5 (form of Flash
> Media Server), code under JSP
> Reporter: Luke Scott
> Assignee: Jochen Wiedmann
>
> I setup an upload script under a JSP. I tested it by uploading a file via
> html form upload and it worked fine - the file was received.
> But when I tried uploading the file through a flash interface using the
> FileReference object I got a 500 error response. Flash's FileReference API
> was very vague, and I was unable to reproduce the error under another
> interface so I could see the error.... But I finnally did get something back
> by writing a catch and writing the error to a file. I don't know if this is
> accurate or not:
> "Stream ended unexpectedly"
> I do know that the error occurs when this line is ran:
> List items = upload.parseRequest(request);
> And here is some relevant code, but not all of it: (to show that I do have a
> factory set):
> DiskFileItemFactory factory = new DiskFileItemFactory();
> factory.setSizeThreshold(524288000);
> ServletFileUpload upload = new ServletFileUpload(factory);
> upload.setSizeMax(524288000);
> List items = upload.parseRequest(request);
> I am fairly sure that flash is doing something that is throwing
> commons-fileupload off. But it does work with apache & php...
> The biggest difference in the headers, or at least the initial headers, is
> flash passes a "connection: close" header.
> When searching I came up with some vague answers. This page shows some
> comments at the bottom by users with similar problems:
> http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002225.html
> One guy posts a solution to fix the problem, but it seems like it is severely
> out of date because where it says "return items;" I do not see items declared
> in the function of the line he mentions. Plus he mentions line 336, and it's
> now on 800 something. Tried his suggestion but instead returned "true" and
> "false" (tried both ways) but it didn't work... Also when I tried his catch
> line ant said it was invalid, so I had to put "Exception e" instead. You may
> notice that his post is in all caps (posts after his appear to be for some
> reason). I did make sure to use the proper case (i do know of case
> sensitivity).
> With further reading I read instances where flash did a "test upload" without
> sending the file. In other cases I read something about it not sending to
> blank lines after the header. Not sure what my current problem is.... I'm
> sure once the problem is found, it should be fairly trivial to fix (i hope).
> Even though it may be flash's fault, it works in PHP and other instances...
> So it should work here :)
> Thanks in advance,
> -Luke
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.