UploadCtxProvider component serves as the root context provider for Uploadcare File Uploader. It manages the upload state, coordinates between components, and emits custom events for all upload-related activities.
Overview
UploadCtxProvider extendsLitUploaderBlock and acts as the central event dispatcher. It binds an internal event emitter to the DOM, allowing you to listen for upload lifecycle events using standard DOM event listeners.
Basic Usage
With Event Listeners
Attributes
Context name that links this provider with other components. All components with the same
ctx-name share state and configuration.Events
UploadCtxProvider emits standard CustomEvents that you can listen to usingaddEventListener. All events carry relevant data in the detail property.
File Events
Fired when a file is added to the upload collection.Detail:
OutputFileEntry<'idle'> - File entry in idle stateFired when a file is removed from the upload collection.Detail:
OutputFileEntry<'removed'> - Removed file entryFired when a file upload begins.Detail:
OutputFileEntry<'uploading'> - File entry in uploading stateFired during file upload to report progress.Detail:
OutputFileEntry<'uploading'> - File entry with progress infoFired when a file upload completes successfully.Detail:
OutputFileEntry<'success'> - Successful file entryFired when a file upload fails.Detail:
OutputFileEntry<'failed'> - Failed file entryFired when a file’s CDN URL changes (e.g., after editing).Detail:
OutputFileEntry<'success'> - File entry with updated URLCollection Events
Fired when batch upload starts for all files.Detail:
OutputCollectionState<'uploading'> - Collection stateFired during batch upload to report overall progress.Detail:
OutputCollectionState<'uploading'> - Collection state with progressFired when all files in the collection upload successfully.Detail:
OutputCollectionState<'success'> - Success stateFired when batch upload fails.Detail:
OutputCollectionState<'failed'> - Failed stateFired whenever the collection state changes.Detail:
OutputCollectionState - Current collection stateFired when files are grouped (when
groupOutput is enabled).Detail: OutputCollectionState<'success', 'has-group'> - State with group infoUI Events
Fired when a modal opens.Detail:
{ modalId: string } - Modal identifierFired when a modal closes.Detail:
{ modalId: string, hasActiveModals: boolean }Fired when the active activity (screen) changes.Detail:
{ activity: string } - Activity nameFired when the upload button is clicked (when
confirmUpload is true).Detail: undefinedFired when the done button is clicked after successful upload.Detail:
OutputCollectionState - Final collection stateTypeScript Support
The component provides full TypeScript support with typed event listeners:Event Access
Event type constants are available on the class:Complete Example
Source Code Reference
Implementation:/workspace/source/src/blocks/UploadCtxProvider/UploadCtxProvider.ts:7
Event definitions: /workspace/source/src/blocks/UploadCtxProvider/EventEmitter.ts:16
See Also
- Config - Configuration component
- UploadList - File list display
- DropArea - File drop zone