Search code examples
jquery-file-uploadblueimp

jQuery File Upload's change callback returns nothing


Everything about the uploader is working perfectly, but one callback seems to do nothing:

.bind('fileuploadchange', function (e, data) {
    console.log("foo");
})

Binding to the change event never returns anything... so my question:

1) Is this a bug? I'm using the most recent version.

2) Is there another/better way to detect when files are manually removed from the upload queue (something more elegant than reading DOM elements)?


Solution

  • There might be a bit of misunderstanding in what the fileuploadchange event does.

    The admittedly limited documentation for the change event states:

    Callback for change events of the fileInput collection.

    That means it's an event callback for the native change event of all the file input elements of the fileupload widget.
    This event only fires if the user selects one or more files via the file picker dialog that is displayed after clicking on the file input button.

    Technically, the basic fileupload library doesn't keep track of a queue. It's up to the UI implementation to handle this, via the various callbacks provided by the basic library.

    Until the user actually starts the file upload, there is technically nothing the basic library could keep track of.
    And as soon as a file upload is started, the done and fail events are your basic building blocks.

    By the way, the sample UI implementation handles the removal of items that have not been started yet by triggering a manual fail event.