Events
The Uploader will trigger for batch and batch-item lifecycle events.
Registering to handle events can be done using the uploader's on() and once() methods. Unregistering can be done using off() or by calling the return value (function) of both on() and once().
See UPLOADER_EVENTS in constants
const batchAddHandler = (batch) => {};
const unregister = uploader.on(UPLOADER_EVENTS.BATCH_ADD, batchAddHandler);
unregister(); //is equivalent to the line below
uploader.off(UPLOADER_EVENTS.BATCH_ADD, batchAddHandler);
BATCH_ADDβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered when a new batch is added.
This event is cancellable
BATCH_STARTβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered when batch items start uploading
The handler can change data inside the items and in the options by returning different data than received.
This event is cancellable
BATCH_PROGRESSβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered every time progress data is received from the upload request(s)
BATCH_FINISHβ
Parameters
: (batch, options: CreateOptions)
Triggered when batch items finished uploading
BATCH_CANCELβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered in case batch was cancelled from BATCH_START event handler
BATCH_ABORTβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered in case the batch was aborted
BATCH_ERRORβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered in case the batch was failed with an error. These errors will most likely occur due to invalid event handling. For instance, by a handler (ex: BATCH_START) throwing an error.
BATCH_FINALIZEβ
Parameters
: (batch: Batch, options: CreateOptions)
Triggered when all batch items have finished uploading or in case the batch was cancelled(abort) or had an error
This event can be relied on to be called regardless of how the batch finished
ITEM_STARTβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered when item starts uploading (just before) For grouped uploads (multiple files in same xhr request) ITEM_START is triggered for each item separately
This event is cancellable
ITEM_FINISHβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered when item finished uploading successfully
The server response can be accessed through the item's uploadResponse property and status code through uploadStatus
ITEM_PROGRESSβ
Parameters
: (item: BatchItem)
Triggered every time progress data is received for this file upload
progress info is accessed through the item's "completed" (percentage) and "loaded" (bytes) properties.
ITEM_CANCELβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered in case item was cancelled programmatically
ITEM_ERRORβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered in case item upload failed
The server response can be accessed through the item's uploadResponse property.
ITEM_ABORTβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered in case abort was called
ITEM_FINALIZEβ
Parameters
: (item: BatchItem, options: CreateOptions)
Triggered for item when uploading is done due to: finished, error, cancel or abort Use this event if you want to handle the state of the item being done for any reason.
This event can be relied on to be called regardless of how the item finished
REQUEST_PRE_SENDβ
Parameters
: (items: BatchItem[], options: CreateOptions)
Triggered before a group of items is going to be uploaded Group will contain a single item unless "grouped" option is set to true.
Handler receives the item(s) in the group and the upload options that were used. The handler can change data inside the items and in the options by returning different data than received. See this guide for more details.
This event is cancellable
ALL_ABORTβ
No parameters
: ()
Triggered when abort is called without an item id (abort all)
Cancellable Eventsβ
These are events that allow the client to cancel their respective upload object (batch or batch-item) To cancel the upload, the handler must return (boolean) false.
uploader.on(UPLOADER_EVENTS.ITEM_START, (item) => {
let result;
if (item.file.name.endsWith(".xml")) {
result = false; //only false will cause a cancel.
}
return result;
});
Chunk Eventsβ
CHUNK_STARTβ
Parameters
: (data: ChunkStartEventData)
Triggered when a chunk begins uploading as part of a chunked upload
- See: ChunkStartEventData
CHUNK_FINISHβ
Parameters
: (data: ChunkFinishEventData)
Triggered when a chunk finishes uploading as part of a chunked upload
- See: ChunkFinishEventData
RETRY_EVENTβ
Triggered when files are re-added to the queue for retry.
Parameters
: ({ uploads: BatchItem[], options?: UploadOptions }
)
uploads is an array of batch items.
options are the (optional) upload options that are passed to the retry call
Tus Eventsβ
RESUME_STARTβ
Parameters
: (data: ResumeStartEventData)
Triggered before the (HEAD) request is issued on behalf of a potentially resumeable upload.
- See: ResumeStartEventData
This event is cancellable
Cancelling the request will not abort the entire upload, but rather cancel the fetching of resume info.