Skip to content

[Feature] CldUploadWidget Events & Instance Methods #156

Closed

Description

@Baroshem

Adds all of the callback options based on events and instance methods as documented: cloudinary.com/documentation/upload_widget_reference#events

Check next-cloudinary solution as reference cloudinary-community/next-cloudinary#255

Activity

  1. added
    enhancement
    hacktoberfest
    on Oct 2, 2023
  2. added this to the 2.4.0 milestone on Oct 4, 2023
  3. khushi2502 commented on Oct 29, 2023

    @khushi2502

    Here is a summary of all of the callback options based on events and instance methods, as documented on the Cloudinary website:

    Events

    show: This event is triggered when the upload widget is displayed.
    shown: This event is triggered after the upload widget has been displayed.
    hide: This event is triggered when the upload widget is hidden.
    hidden: This event is triggered after the upload widget has been hidden.
    progress: This event is triggered periodically as the upload progresses.
    success: This event is triggered when the upload is successful.
    error: This event is triggered when the upload fails.

    Instance methods
    open(): Opens the upload widget.
    close(): Closes the upload widget.
    destroy(): Destroys the upload widget instance.
    Next-Cloudinary solution

    The Next-Cloudinary solution uses the show and hide events to display and hide the upload widget. It also uses the success event to handle successful uploads.

    The following code shows how to use the Next-Cloudinary solution to display the upload widget:

    import CloudinaryUploadWidget from '@cloudinary/next-cloudinary-widget';

    const UploadWidget = () => {
    const [widget, setWidget] = useState(null);

    const openWidget = () => {
    const widget = new CloudinaryUploadWidget({
    cloudName: 'my-cloud-name',
    uploadPreset: 'my-upload-preset',
    });

    widget.on('show', () => {
      // The upload widget is displayed.
    });
    
    widget.on('hidden', () => {
      // The upload widget is hidden.
    });
    
    widget.on('success', (result) => {
      // The upload was successful.
      // Handle the result here.
    });
    
    setWidget(widget);
    widget.open();
    

    };

    const closeWidget = () => {
    if (widget) {
    widget.close();
    }
    };

    return (
    Open Upload Widget
    );
    };

    export default UploadWidget;

    This code will create a new CloudinaryUploadWidget instance and open it when the user clicks the button. The show, hidden, and success events will be handled to display and hide the upload widget, and to handle successful uploads.

  4. Baroshem commented on Oct 30, 2023

    @Baroshem
    CollaboratorAuthor

    Hey @khushi2502

    The idea of this issue was to implement these events and instance methods in the Nuxt Cloudinary based on NextCloudinary.

    Would you be interested in contributing? :)

  5. khushi2502 commented on Oct 30, 2023

    @khushi2502
  6. Baroshem commented on Oct 30, 2023

    @Baroshem
    CollaboratorAuthor

    It is all in the linked PR from NextCloudinary.

    Currently, the component CldUploadWidget in Nuxt Cloudinary (this project) works but it could certainly accept some events and instance methods that are already available in the Next Cloudinary.

    So the idea is basically to achieve the same as in the linked PR in this repo :)

  7. khushi2502 commented on Oct 30, 2023

    @khushi2502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhacktoberfest

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions