Search code examples
javascriptuploadcare

UploadCare doesn't load image in dialog


I expect the UploadCare dialog to open after clicking MyButton, showing the Twitter logo, but it doesn't. Why not?

$('#MyButton').on('click', function() {
    uploadcare.openDialog('https://g.twimg.com/About_logoUsage.png');
    return false;
});

Solution

  • You need to pass a file object as an argument to openDialog method. You can obtain the file object by calling uploadcare.fileFrom method:

    // Pre-load an image from arbitrary URL,
    // and open Uploadcare file upload dialog
    $('#MyButton').on('click', function() {
        var file = uploadcare.fileFrom('url', 'https://g.twimg.com/About_logoUsage.png');
        uploadcare.openDialog(file);
        return false;
    });