CldUploadWidget Configuration
Basic Props
Prop | Type | Example | |
---|---|---|---|
children | function | {(options) => {}} | |
signatureEndpoint | string | /api/sign-cloudinary-params.js | More Info |
uploadPreset | string | my-upload-preset | More Info (opens in a new tab) |
children
A function that returns a React component that receives instance methods and options for the widget.
<CldUploadWidget uploadPreset="<Upload Preset>">
{({ open }) => {
return (
<button className="button" onClick={() => open()}>
Upload
</button>
);
}}
</CldUploadWidget>
Parameters
By passing in a function as the child of the Upload Widget, you're able to gain access to the widget, results, and instance methods to interface directly with the widget.
Prop | Type | Description |
---|---|---|
cloudinary | Cloudinary | The Cloudinary instance which creates and manages the Widget instance. |
error | string | The error, if any, produced by an upload widget action. |
isLoading | boolean | Designates whether the upload widget is loading and initializing. |
results | object | The event that triggered the results and information related to that event, which can include upload results. |
widget | Widget | The widget instance attached to the current component. |
[Instance Methods] | Function | See Instance Methods below |
Example
<CldUploadWidget>
{({ cloudinary, widget, open }) => {
// Return UI
}}
</CldUploadWidget>
signatureEndpoint
An API endpoint used to sign the parameters generated during upload.
signatureEndpoint="/api/sign-cloudinary-params"
Learn more about generating signatures (opens in a new tab) on the Cloudinary docs.
uploadPreset
uploadPreset="my-upload-preset"
Learn more about upload presets (opens in a new tab) on the Cloudinary docs.
Events
Upload Widget events allow you to tap into different points of the upload lifecycle including when an upload has completed, but also when it starts the queue and more. To allow interaction with these events, CldUplodWidget provides both "Callback Functions" and "Actions".
The difference between the Callback Functions and the Actions is the second argument of options that the Callback Functions receive. While Callback Functions pass in both the results along with the widget instance and instance methods, Actions only pass along the results in order to support the Server Actions workflow.
Callback Functions
Prop | Type | Example | |
---|---|---|---|
onAbort | function | (results, options) => { } | More Info (opens in a new tab) |
onBatchCancelled | function | (results, options) => { } | More Info (opens in a new tab) |
onClose | function | (results, options) => { } | More Info (opens in a new tab) |
onDisplayChanged | function | (results, options) => { } | More Info (opens in a new tab) |
onError | function | (error, options) => { } | |
onOpen | function | (widget) => { } | |
onPublicId | function | (results, options) => { } | More Info (opens in a new tab) |
onQueuesEnd | function | (results, options) => { } | More Info (opens in a new tab) |
onQueuesStart | function | (results, options) => { } | More Info (opens in a new tab) |
onRetry | function | (results, options) => { } | More Info (opens in a new tab) |
onShowCompleted | function | (results, options) => { } | More Info (opens in a new tab) |
onSourceChanged | function | (results, options) => { } | More Info (opens in a new tab) |
onSuccess | function | (results, options) => { } | More Info (opens in a new tab) |
onTags | function | (results, options) => { } | More Info (opens in a new tab) |
onUpload (Deprecated) | function | (results, widget) => { } | |
onUploadAdded | function | (results, options) => { } | More Info (opens in a new tab) |
Actions
Prop | Type | Example | |
---|---|---|---|
onAbortAction | function | (results) => { } | More Info (opens in a new tab) |
onBatchCancelledAction | function | (results) => { } | More Info (opens in a new tab) |
onCloseAction | function | (results) => { } | More Info (opens in a new tab) |
onDisplayChangedAction | function | (results) => { } | More Info (opens in a new tab) |
onPublicIdAction | function | (results) => { } | More Info (opens in a new tab) |
onQueuesEndAction | function | (results, options) => { } | More Info (opens in a new tab) |
onQueuesStartAction | function | (results) => { } | More Info (opens in a new tab) |
onRetryAction | function | (results) => { } | More Info (opens in a new tab) |
onShowCompletedAction | function | (results) => { } | More Info (opens in a new tab) |
onSourceChangedAction | function | (results) => { } | More Info (opens in a new tab) |
onSuccessAction | function | (results) => { } | More Info (opens in a new tab) |
onTagsAction | function | (results) => { } | More Info (opens in a new tab) |
onUploadAddedAction | function | (results) => { } | More Info (opens in a new tab) |
To learn more about the event callbacks and when they trigger, see: https://cloudinary.com/documentation/upload_widget_reference#events (opens in a new tab)
Example
<CldUploadWidget
...
onSuccess={(results) => {
console.log('Public ID', results.info.public_id);
}}
/>
Callback Parameters
Most of the callbacks provide a set of options that give access to the results, options, and widget instance.
Prop | Type | Description |
---|---|---|
error | string | If an error occurs, an explanation of what failed. |
options | object | Instance methods and the widget instance. |
results | object | The event that drove the callback and the info pertaining to the event (such as a resource). |
Future releases will work to create a more consistent interface between older methods and more recently added methods.
Example
<CldUploadWidget
...
onSuccess={(results) => {
console.log('Public ID', results.info.public_id);
}}
/>
options
Prop | Type | Description |
---|---|---|
widget | Widget Instance | The Cloudinary Upload Widget instance being rendered. |
[Instance Methods] | Function | See Instance Methods below |
results
The event and results that were returned from the event.
Prop | Type | Description |
---|---|---|
event | string | The event that triggered the callback. |
info | string | object | Information pertaining to the triggered event, such as the resulting uploaded resource. |
A common use of results could be to retrieve an uploaded asset, which would be made available in the info
property
from the resulting event. If the result is a resource, the shape will include some of the following details.
Example
{
height: 400;
public_id: 'mypublicid';
secure_url: 'https://res.cloudinary.com/.../mypublicid';
width: 400;
...
}
Instance Methods
The Upload Widget exposes instance methods that gives the ability to have greater control and flexbility over the upload experience.
They're exposed either through event handler callback or child function parameters.
Prop | Type | Description |
---|---|---|
close | function | Closes and resets the widget to its initial state without removing it from memory. |
destroy | function | Hides a previously rendered widget while retaining its current state in memory. |
hide | function | Closes the widget and completely removes it from the DOM. Returns a promise that resolves upon cleanup completion. |
isDestroyed | function | Returns whether the destroy method was called on this instance. |
isMinimized | function | Returns whether the widget is currently minimized. |
isShowing | function | Returns whether the widget is currently visible. |
minimize | function | Minimizes the widget. |
open | function | Renders an existing widget currently in memory, but that is not currently displayed. |
show | function | Renders a previously hidden widget. |
update | function | Updates a widget currently in memory with new options. |
Advanced
Configuration
Prop | Type | Default | Example | |
---|---|---|---|---|
config | object | - | { url: { cloudName: 'spacejelly' } } | More Info (opens in a new tab) |
options | object | {encryption: {...}} | More Info (opens in a new tab) |
config
Allows configuration for the Cloudinary environment.
Examples
config={{
cloud: {
cloudName: '<Your Cloud Name>',
apiKey: '<Your API Key>'
}
}}
options
Parameters used to customize and configure the Upload Widget instance. These options are passed in
directly to the Upload Widget, exposing all available parameters through the options
object.
options={{
sources: ['local', 'url', 'unsplash'],
multiple: true,
maxFiles: 5
}}
Learn more about Upload Widget parameters (opens in a new tab) on the Cloudinary docs.