Skip to content

Add ability to cancel an update in the onBeforeUploadItem event - #624

Closed
mrpmorris wants to merge 1 commit into
nervgh:masterfrom
mrpmorris:master
Closed

mrpmorris wants to merge 1 commit into
nervgh:masterfrom
mrpmorris:master

Conversation

@mrpmorris

Copy link
Copy Markdown

This enables the consumer of the onBeforeUploadItem event to cancel the upload just at the point it is about to be uploaded. This is useful for checking conditions at the point of upload which may have changed from the point it was added to the queue.

By default the result of onBeforeUploadItem will return true, causing the library to act in exactly the same way it does now - if the event handler returns false then the update is cancelled.

@mrpmorris

Copy link
Copy Markdown
Author

How do I know when/if this is merged into branch, will github email me or anything?

@nervgh

nervgh commented May 8, 2016 •

Copy link
Copy Markdown
Owner

Thank you!

Looks like the diff very big 649c62b#diff-52bbcc9546e5ba6702743aad877b3f4f

What you think about this?

/**
 * The XMLHttpRequest transport
 * @param {FileItem} item
 * @private
 */
_xhrTransport(item) {
    var xhr = item._xhr = new XMLHttpRequest();
    var form = new FormData();

    if (this._onBeforeUploadItem(item)) {
        this._onCancelItem(item);
        this._onCompleteItem(item);
        return;
    }
/**
 * Uploads a item from the queue
 * @param {FileItem|Number} value
 */
uploadItem(value) {
   // ...
   this[transport](item);
   this._render(); // <--
}

Please, see also that comment.

@mrpmorris

Copy link
Copy Markdown
Author

That looks like it will work :)

Do you want/need me to do anything, or do you intend just to change it yourself ?

@nervgh

nervgh commented May 20, 2016

Copy link
Copy Markdown
Owner

Please

  1. decrease difference size of your PR if it possible
  2. remove bundled files from your PR
@nervgh

nervgh commented May 26, 2016

Copy link
Copy Markdown
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants