You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bruno P. Kinoshita (JIRA)" <ji...@apache.org> on 2017/06/11 03:53:19 UTC

[jira] [Comment Edited] (FILEUPLOAD-142) ProgressListener and Streaming API improvement

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

Bruno P. Kinoshita edited comment on FILEUPLOAD-142 at 6/11/17 3:52 AM:
------------------------------------------------------------------------

I ran into the same problem and created a patch for Fileupload along the lines suggested above.

Instead of changing any existing interface or classes, my patch simply adds a new interface, FileItemListener, which only reports on when new FileItems are found.

{noformat}
+public interface FileItemListener
+{
+    /**
+     * Called when processing the upload to indicate that
+     * a new item is discovered.
+     *
+     * @param contentType
+     *        The string that would have been
+     *        returned by FileItem.getContentType().
+     *
+     * @param fieldName
+     *        The string that would have been
+     *        returned by FileItem.getFieldName().
+     *
+     * @param name
+     *        The string that would have been
+     *        returned by FileItem.getName().
+     *
+     * @param isFormField
+     *        The string that would have been
+     *        returned by FileItem.isFormField().
+     *
+     */
+    void newItem(String contentType,
+                 String fieldName,
+                 String name,
+                 boolean isFormField);
+}
{noformat}

My intention was to make the smallest possible change, in order to not break any existing apps.  If someone doesn't want the new functionality they can ignore it without any difficulty.  If they do need to find out information on FileItems, a user can implement this interface.

Having two interfaces (rather than just extending ProgressListener) is a bit awkward, but it's a more friendly approach towards existing users of ProgressListener.

If you have any questions about this change, just let me know.



was (Author: chrisrude):
I ran into the same problem and created a patch for Fileupload along the lines suggested above.

Instead of changing any existing interface or classes, my patch simply adds a new interface, FileItemListener, which only reports on when new FileItems are found.

+public interface FileItemListener
+{
+    /**
+     * Called when processing the upload to indicate that
+     * a new item is discovered.
+     *
+     * @param contentType
+     *        The string that would have been
+     *        returned by FileItem.getContentType().
+     *
+     * @param fieldName
+     *        The string that would have been
+     *        returned by FileItem.getFieldName().
+     *
+     * @param name
+     *        The string that would have been
+     *        returned by FileItem.getName().
+     *
+     * @param isFormField
+     *        The string that would have been
+     *        returned by FileItem.isFormField().
+     *
+     */
+    void newItem(String contentType,
+                 String fieldName,
+                 String name,
+                 boolean isFormField);
+}

My intention was to make the smallest possible change, in order to not break any existing apps.  If someone doesn't want the new functionality they can ignore it without any difficulty.  If they do need to find out information on FileItems, a user can implement this interface.

Having two interfaces (rather than just extending ProgressListener) is a bit awkward, but it's a more friendly approach towards existing users of ProgressListener.

If you have any questions about this change, just let me know.


> ProgressListener  and Streaming API improvement
> -----------------------------------------------
>
>                 Key: FILEUPLOAD-142
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-142
>             Project: Commons FileUpload
>          Issue Type: Improvement
>    Affects Versions: 1.2.2
>         Environment: ANY
>            Reporter: Bohdan Bobylak
>            Priority: Minor
>         Attachments: fileupload-142.patch
>
>
> This relates to the "Watching progress"  section of the FileUpload "User Guide".
> As we know the ProgressListener has the only method:  void update(long pBytesRead, long pContentLength, int pItems) ;
> And it passes only:
>     pBytesRead - The total number of bytes, which have been read so far.
>     pContentLength - The total number of bytes, which are being read.
>     pItems - The number of the field, which is currently being read.
> It would be great to have access to some basic info about item currently uploaded from the 'update' method.
> For example: in some cases (ex.: multipart/replace response) it is needed to skip field items and output progress info only about file(s) being uploaded.
> I think the following changes will help:
> ==========================================
> ----------------------------------------------------------
> 1. Introduce new interface:
> {code:java}
> interface Item {
>    String 	getContentType()
>    String 	getFieldName()
>    String 	getName()
>   boolean   isFormField() 
> }
> {code}
> ---------------------------------------------------------
> 2. Change (or and new) 'update' method:
> {code:java}
> void update(long pBytesRead, long pContentLength, int pItems, Item item) ;
> {code}
> Here we pass Item - not the FileItemSteam referense becase we should not be able to access openStream() method of the FileItemStream.
> ---------------------------------------------------------
> 3. Change FileItemStream interface as follows:
> {code:java}
> interface FileItemStream extends Item{
>    java.io.InputStream 	openStream();
> }
> {code}
> ... and change FileItemStreamImpl implementation (if needed)
> ----------------------------------------------------------
> 4. Change ProgressNotifier as follows:
> {code:java}
> static class ProgressNotifier {
>     .....
>     // Add this field
>     private Item curItem;
>     .....
>     // Change the noteItem() method as follows
>      void noteItem(Item item) {
>               ++items;
>               curItem = item;    
>      }
>      // Change the notifyListener() method
>     private void notifyListener() {
>         if (listener != null) {
>             listener.update(bytesRead, contentLength, items, curItem);
>         }
>     }
> }
> {code}
> --------------------------------------------------------------
> 5. Change calls from 'notifier.noteItem()' to 'notifier.noteItem(currentItem)' in the
>     FileItemIteratorImpl.findNextItem() method of the  FileUploadBase file.
> ====================================
> Hope my explanation of the improvement is clear.
> Thank you.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)