5

My scenario - I would like to open an upload dialog from my own button and get the uploaded file info. In Uploadcare JS version 0.12 I did the following:

$(".upload-image-button").on("click", function() {
  uploadcare.openDialog(null, {
    imagesOnly: true
  }).uploadDone(function(info) {
    setImage(info.cdnUrl);
  });
});

In 0.16 there's no more uploadDone and all it does is return a promise without any data. What should I do?

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
Alexander Shtuchkin
  • 1,797
  • 15
  • 20

1 Answers1

6

uploadDone was never part of public API and was not mentioned in documentation, so it was removed. uploadcare.openDialog always returns promise object with selected file (or group of files for multiupload dialogs). But file is promise itself: it resolves when uploading is complete. So to access uploading info you should subscribe to file.done:

$(".upload-image-button").on("click", function() {
    uploadcare.openDialog(null, {
        imagesOnly: true
    }).done(function(file) {
        file.done(function(fileInfo) {
            setImage(fileInfo.cdnUrl);
        });
    });
});
Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
  • @AlexanderShtuchkin Does above exact code work for multi uploads? – bart Sep 26 '18 at 06:17
  • @bart, this will not work for multi-upload, this may help: https://kb.uploadcare.com/article/213-how-to-get-individual-file-uuids-from-a-multiupload – Dmitry Mukhin Sep 27 '18 at 09:41