For jQuery plug-in users, adhere to the following syntax:
$('#myUploader')
.on('complete', function(event, id, name, response) {
...
})
.on('cancel', function(event, id, name) {
...
});
Note that, if using the jQuery plug-in, you can also bind your callback/event handlers as part of your initialization code, since
the fineUploader
plug-in returns your target element ($('#myUploader')
, in this example).
Callbacks must be declared inside of a callbacks
object for non-jQuery users, like this:
new qq.FineUploader({
...
callbacks: {
onComplete: function(id, name, response) {
...
},
onCancel: function(id, name) {
...
},
...
}
}
### List of callbacks ###
onSubmit(String id, String name)
- called when the file orBlob
is submitted to the uploader portion of the code. Note that this does not mean the file upload will begin at this point. Returnfalse
to prevent submission to the uploader.onComplete(String id, String name, Object responseJSON)
- called when the file orBlob
upload has finished. A successful upload will always have asuccess
property in theresponseJSON
object with a value oftrue
. TheresponseJSON
parameter will also contain any other elements of the JSON response returned by the server.onCancel(String id, String name)
- called when the file orBlob
upload has been cancelled.onUpload(String id, String name)
- called just before a file orBlob
upload begins.onUploadChunk(String id, String name, Object chunkData)
- called just before aFile
/Blob
chunk/partition request is sent. The chunkData object has 4 properties:partIndex
(the 0-based index of the associated partition),startByte
(the byte offset of the current chunk in terms of the underlyingFile
/Blob
),endByte
(the last byte of the current chunk in terms of the underlyingFile
/Blob
), andtotalParts
(the total number of partitions associated with the underlyingFile
/Blob
).onProgress(String id, String name, int uploadedBytes, int totalBytes)
- called during the upload, as it progresses. Only used by the XHR/ajax uploader.onError(String id, String name, String errorReason)
- called whenever an exceptional condition occurs (during an upload, file selection, etc).onAutoRetry(String id, String name, String attemptNumber)
- called before each automatic retry attempt for a failed file orBlob
.onManualRetry(String id, String name)
- called before each manual retry attempt. Return false to prevent this and all future retry attempts on this file orBlob
.onResume(String id, String fileName, Object chunkData)
- Called before an attempt is made to resume a failed/stopped upload from a previous session. If you return false, the resume will be cancelled and the uploader will start uploading the file from the first chunk. ThechunkData
object contains the properties as thechunkData
parameter passed into theonUploadChunk
callback.onValidate(FileOrBlobData fileOrBlobData)
- This callback represents one of the files orBlob
s selected for upload. It is called once for each selected, dropped, oraddFiles
submitted file and for eachaddBlobs
submittedBlob
, provided you do not return false in youronValidateBatch
handler, and also provided thestopOnFirstInvalidFile
validation option is not set and a previous invocation of youronValidate
callback in this batch has not returned false. This callback is always invoked before the default Fine Uploader validators execute. Note that aFileOrBlobData
object has two properties:name
andsize
. Thesize
property will be undefined if the user agent does not support the File API.onValidateBatch(Array fileOrBlobDataArray)
- This callback is invoked once for each batch of files orBlob
s selected, dropped, or submitted via theaddFiles
oraddBlobs
API functions. A FileOrBlobData array is passed in representing all files orBlob
s selected or dropped at once. This allows you to prevent the entire batch from being uploaded, if desired, by returning false. If your handler does not return false, theonValidate
callback will be invoked once for each individual file orBlob
submitted. This callback is always invoked before the default Fine Uploader validators execute. Note that aFileOrBlobData
object has two properties:name
andsize
. Thesize
property will be undefined if the user agent does not support the File API.onSubmitDelete(id)
- Called before a file orBlob
that has been marked for deletion has been submitted to the uploader. You may return false from your handler if you want to ignore/stop the delete request.onDelete(id)
- Called just before a delete request is sent for the associated file orBlob
. The parameter is the ID.onDeleteComplete(id, xhr, isError)
- Called after receiving a response from the server for a DELETE request. The associated ID, along with the request's XMLHttpRequest object and a boolean indicating whether the response succeeded or not (based on the response code) are sent along as parameters.