UploadCare doesn't show alert upon closing dialog

350 Views Asked by At

When the UploadCare dialog is closed I expect the alert to show, but it doesn't. Why not?''

$('#uc_open').on('click', function() {
    uploadcare.openDialog(null, {
        imagesOnly: true
        }).done(function(file) {
            file.done(function(fileInfo) {
                //
            }).fail(function(error, fileInfo) {
                alert(error);
            });
        });
    return false;
});
1

There are 1 best solutions below

1
On BEST ANSWER

You have subscribed to openDialog().done(). This callback will be called when user choose a file and click "done" in dialog. In this callback you receive file object and subscribe to file.fail() callback. This callback will be called when file uploading will be failed due to network error or unsatisfied validators.

If you want to subscribe to callback when user close dialog without choosing file (by clicking × in upper right corner, or by pressing ESC), you should subscribe to openDialog().fail():

$('#uc_open').on('click', function() {
    // Open the dialog on button cick
    uploadcare.openDialog(null, {
        imagesOnly: true
        }).done(function(file) {
            // User has just clicked "Done" in Uploadcare dialog
            file.done(function(fileInfo) {
                // File uploading succeeded
            });
        }).fail(function(error, fileInfo) {
            // User just has closed the dialog by pressing ESC or clicking on "×"
            alert(error);
        });
    return false;
});