Search code examples
javascriptnode.jsfile-uploaduploadcare

how to reset uploadcare widget to original state after the file upload is complete


I am using Uploadcare widget to upload profile images in an nodejs app. In Uploadcare widget once user is done uploading a single file, I want to go back to original widget state so the user can choose another image to replace the previous one.

widget.onUploadComplete(function(info) {
    // assign image to image tag
    $('#avatar').attr('src', info.cdnUrl);

    // reset the widget to user can see the the "choose image" button again. 
    widget.value();
}

However the widget.value() doesn't seem to do anything although that is suggested on issue on uploadcare


Solution

  • widget.value is getter/setter method, so widget.value() will just return current value.

    Use widget.value(null) to reset.

    You can find more in Uploadcare JS API documentation.

    p.s.: thanks for the tip, I have improved an answer in github issue.