You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2013/03/10 12:27:13 UTC

[jira] [Commented] (FILEUPLOAD-179) ProgressListener doesn't work on Streaming API

    [ https://issues.apache.org/jira/browse/FILEUPLOAD-179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13598213#comment-13598213 ] 

Thomas Neidhart commented on FILEUPLOAD-179:
--------------------------------------------

I did a similar test as with your other example, this time using the streaming API:

{noformat}
    @Test
    public void testProgressListener()
            throws IOException, FileUploadException {
        final String request =
            "-----1234\r\n" +
            "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
            "Content-Type: text/whatever\r\n" +
            "Content-Length: 10\r\n" +
            "\r\n" +
            "This is the content of the file\n" +
            "\r\n" +
            "-----1234--\r\n";

        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
        upload.setFileSizeMax(Long.MAX_VALUE);
        HttpServletRequest req = new MockHttpServletRequest(request.getBytes("US-ASCII"), CONTENT_TYPE);

        FileUploadListener listener = new FileUploadListener();
        upload.setProgressListener(listener);
        
        // Parse the request
        FileItemIterator iter = upload.getItemIterator(req);
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            String name = item.getFieldName();
            InputStream stream = item.openStream();
            if (item.isFormField()) {
                System.out.println("Form field " + name + " with value "
                    + Streams.asString(stream) + " detected.");
            } else {
                System.out.println("File field " + name + " with file name "
                    + item.getName() + " detected.");
                // Process the input stream
            }
        }
    }

    public class FileUploadListener implements ProgressListener
    {
       public void update(long aBytesRead, long aContentLength, int anItem)     
       {
           assertTrue(aBytesRead > 0);
           System.out.println(aBytesRead + " " + aContentLength + " " + anItem);
       }
    }
{noformat}

The result is the same:

{noformat}
174 -1 0
174 -1 1
File field file with file name foo.tab detected.
{noformat}
                
> ProgressListener doesn't work on Streaming API
> ----------------------------------------------
>
>                 Key: FILEUPLOAD-179
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-179
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>         Environment: Tomcat 6.0.24
>            Reporter: Björn Agel
>              Labels: fileupload, progress_listener, streaming_api
>
> When using the Streaming API the update()-method of my ProgressListener is not being called. If I use the parseRequest()-method instead the update()-method is called as expected. Any hints?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira