File Uploader data output and event handling
Warning: In the v0.32.0 release, global events are removed and all the existing events are updated. See the migration guide.
All the File Uploader events are dispatched on the uc-upload-ctx-provider tag.
You can catch them with the native addEventListener method, or use api.on() as a programmatic alternative that returns an unsubscribe function.
Attribute ctx-name is required for the uc-upload-ctx-provider tag, see
Context for more details.
Quick start: log common events
If you want to quickly inspect what happens during the upload lifecycle, add listeners for the most common events and log event.detail to the console.
Warning: Use console.log only for debugging. In production, connect these events to your analytics or telemetry system. Avoid logging PII.
Available events
In the event types below, we mention a few external types that aren’t described on this page:
OutputFileEntry: see OutputFileEntry for more details.OutputCollectionState: see OutputCollectionState for more details.
An OutputCollectionState payload is filled on demand. Read it in the handler,
or keep e.detail.snapshot() (or {...e.detail}) to read it later; see
Reading the state.
file-added
Type: CustomEvent<OutputFileEntry>
Dispatched when a file is added to the upload list. The OutputFileEntry
instance is in idle state, or success for a file added already uploaded with
addFileFromUploadcareFile(). Could be suppressed if the silent option is set to
true.
file-removed
Type: CustomEvent<OutputFileEntry>
Dispatched when a file is removed from the upload list. The OutputFileEntry
instance is in removed state.
file-upload-start
Type: CustomEvent<OutputFileEntry>
Dispatched when a file upload starts. The OutputFileEntry instance is in
uploading state. Could be suppressed if the silent option is set to true.
file-upload-progress
Type: CustomEvent<OutputFileEntry>
Dispatched when a file upload progress changes. The OutputFileEntry instance
is in uploading state. Could be suppressed if the silent option is set to
true.
file-upload-success
Type: CustomEvent<OutputFileEntry>
Dispatched when a file upload is successfully finished. The OutputFileEntry
instance is in success state. Could be suppressed if the silent option is set
to true.
file-upload-failed
Type: CustomEvent<OutputFileEntry>
Dispatched when a file upload fails. The OutputFileEntry instance is in
failed state.
Since v1.37.0 It is dispatched once for each failure. Validators run again when the file or the config changes; a run that finds the same errors does not dispatch it again.
file-url-changed
Type: CustomEvent<OutputFileEntry>
Dispatched when a file CDN URL is changed. This occurs when a file is
uploaded and the CDN URL becomes available, or when a file is edited with the
Image editor that changes the CDN URL. A file
added with addFileFromCdnUrl() gets its URL before it uploads, so the
OutputFileEntry can be in any state.
modal-open
Type: CustomEvent<{modalId: "start-from" | "camera" | "upload-list" | "url" | "cloud-image-edit" | "external" }>
modalId tells you which modal opened. It can also be the id
of an activity registered by a plugin.
Available in: regular and minimal modes
Dispatched when the modal is opened. Each activity shown in the modal counts as
a modal of its own: when the open modal switches from one activity to another,
modal-open is dispatched for the new activity, then
modal-close for the previous one.
modal-close
Type: CustomEvent<{modalId: "start-from" | "camera" | "upload-list" | "url" | "cloud-image-edit" | "external"; hasActiveModals: boolean }>
modalId – a field that lets you know which modal used.
hasActiveModals – a field that lets you know if any modals are active at the moment.
Available in: regular and minimal modes
Dispatched when the modal is closed, and for the previous activity when the open
modal switches to another one. A switch from start-from to camera
dispatches:
modal-openwith{ modalId: 'camera' }modal-closewith{ modalId: 'start-from', hasActiveModals: true }
When the modal is closed, hasActiveModals is false.
done-click
Type: CustomEvent<OutputCollectionState>
Available in: regular and inline modes
Dispatched when the Done button is clicked.
upload-click
Type: CustomEvent<void>
Available in: regular and inline modes
Dispatched when the Upload button is clicked.
activity-change
Type: CustomEvent<{ activity: "start-from" | "camera" | "upload-list" | "url" | "cloud-image-edit" | "external" | null }>
Dispatched when the activity changes. activity can also be the id of an
activity registered by a plugin.
common-upload-start
Type: CustomEvent<OutputCollectionState>
Dispatched when an upload process starts, once its first file is uploading. The
OutputCollectionState instance is in uploading status, or failed when the
list already holds a file with an error. It isn’t dispatched when validation
rejects every file.
It could be triggered in the following cases:
- When the
confirmUploadoption isfalse(the default) and files are added. - When the upload process is started using the API.
- When the user clicks the Upload button.
common-upload-progress
Type: CustomEvent<OutputCollectionState>
Dispatched when an upload process progress changes. The OutputCollectionState
instance is usually in uploading status. It is failed when a file in the list
has an error, and the last event can come once the upload has settled.
The progress is calculated for those files that were ready to upload at the moment when the upload process was started. That means, for example, if there were 3 uploaded files in the list, and the user added 2 more files, the progress will be calculated for those 2 new files only.
common-upload-success
Type: CustomEvent<OutputCollectionState>
Dispatched when an upload process is successfully finished. The
OutputCollectionState instance is in success status.
The upload process is considered as successfully finished when all the files in the
list are successfully uploaded. If there are any uploading, failed or idle
files, the upload process isn’t considered as successfully finished.
common-upload-failed
Type: CustomEvent<OutputCollectionState>
Dispatched when an upload process fails. The OutputCollectionState instance is
in failed status.
The upload process is considered as failed when any of the file in the list is
in a failed status, or the list has a collection error, such as too many
files. Since v1.37.0 It’s dispatched once nothing in the list is still
uploading or being validated: a file that fails while others still upload is
reported when the last of them finishes. It’s dispatched again only when
something new fails, not when validators run again and find the same errors.
The payload lists every failed file, not only the new ones.
change
Type: CustomEvent<OutputCollectionState>
Dispatched when the upload list changes. Any change in the upload list itself or in the files state will trigger this event.
group-created
Type: CustomEvent<OutputCollectionState>
Dispatched when a group is created. Group will be created when the
groupOutput option is set to
true and when the upload process is considered as successfully finished.
The group belongs to the files it was created from. When a file is added or
removed, or a file’s URL changes (after editing it in the image editor, for
example), a new group is created for the files as they are now, once they have all
uploaded, and group-created is dispatched again.