Next Cloudinary v6 now available! View Changelog

<CldUploadWidget />
Configuration

CldUploadWidget Configuration

Basic Props

PropTypeExample
childrenfunction{(options) => {}}
signatureEndpointstring/api/sign-cloudinary-params.jsMore Info
uploadPresetstringmy-upload-presetMore 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.

PropTypeDescription
cloudinaryCloudinaryThe Cloudinary instance which creates and manages the Widget instance.
errorstringThe error, if any, produced by an upload widget action.
isLoadingbooleanDesignates whether the upload widget is loading and initializing.
resultsobjectThe event that triggered the results and information related to that event, which can include upload results.
widgetWidgetThe widget instance attached to the current component.
[Instance Methods]FunctionSee 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

PropTypeExample
onAbortfunction(results, options) => { }More Info (opens in a new tab)
onBatchCancelledfunction(results, options) => { }More Info (opens in a new tab)
onClosefunction(results, options) => { }More Info (opens in a new tab)
onDisplayChangedfunction(results, options) => { }More Info (opens in a new tab)
onErrorfunction(error, options) => { }
onOpenfunction(widget) => { }
onPublicIdfunction(results, options) => { }More Info (opens in a new tab)
onQueuesEndfunction(results, options) => { }More Info (opens in a new tab)
onQueuesStartfunction(results, options) => { }More Info (opens in a new tab)
onRetryfunction(results, options) => { }More Info (opens in a new tab)
onShowCompletedfunction(results, options) => { }More Info (opens in a new tab)
onSourceChangedfunction(results, options) => { }More Info (opens in a new tab)
onSuccessfunction(results, options) => { }More Info (opens in a new tab)
onTagsfunction(results, options) => { }More Info (opens in a new tab)
onUpload (Deprecated)function(results, widget) => { }
onUploadAddedfunction(results, options) => { }More Info (opens in a new tab)

Actions

PropTypeExample
onAbortActionfunction(results) => { }More Info (opens in a new tab)
onBatchCancelledActionfunction(results) => { }More Info (opens in a new tab)
onCloseActionfunction(results) => { }More Info (opens in a new tab)
onDisplayChangedActionfunction(results) => { }More Info (opens in a new tab)
onPublicIdActionfunction(results) => { }More Info (opens in a new tab)
onQueuesEndActionfunction(results, options) => { }More Info (opens in a new tab)
onQueuesStartActionfunction(results) => { }More Info (opens in a new tab)
onRetryActionfunction(results) => { }More Info (opens in a new tab)
onShowCompletedActionfunction(results) => { }More Info (opens in a new tab)
onSourceChangedActionfunction(results) => { }More Info (opens in a new tab)
onSuccessActionfunction(results) => { }More Info (opens in a new tab)
onTagsActionfunction(results) => { }More Info (opens in a new tab)
onUploadAddedActionfunction(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.

PropTypeDescription
errorstringIf an error occurs, an explanation of what failed.
optionsobjectInstance methods and the widget instance.
resultsobjectThe 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

PropTypeDescription
widgetWidget InstanceThe Cloudinary Upload Widget instance being rendered.
[Instance Methods]FunctionSee Instance Methods below

results

The event and results that were returned from the event.

PropTypeDescription
eventstringThe event that triggered the callback.
infostring | objectInformation 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.

PropTypeDescription
closefunctionCloses and resets the widget to its initial state without removing it from memory.
destroyfunctionHides a previously rendered widget while retaining its current state in memory.
hidefunctionCloses the widget and completely removes it from the DOM. Returns a promise that resolves upon cleanup completion.
isDestroyedfunctionReturns whether the destroy method was called on this instance.
isMinimizedfunctionReturns whether the widget is currently minimized.
isShowingfunctionReturns whether the widget is currently visible.
minimizefunctionMinimizes the widget.
openfunctionRenders an existing widget currently in memory, but that is not currently displayed.
showfunctionRenders a previously hidden widget.
updatefunctionUpdates a widget currently in memory with new options.

Advanced

Configuration

PropTypeDefaultExample
configobject-{ url: { cloudName: 'spacejelly' } }More Info (opens in a new tab)
optionsobject {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.