3

I'm trying to get my head around the Uploadcare API. Please excuse my ignorance for the question below.

I have the Uploadcare uploader set to a maximum of 5 images. This appears to upload the files to Uploadcare correctly.

What I'm trying to do is grab hold of the newly created UUID of the file and store it in a form field for posting to my server side app to process some other data and to store the UUID so the file can be processed via the REST api.

In the end I'm simply trying to capture the information and generate dynamically created hidden fields of the UUID so I can store them in a database.

If I'm going in the completely wrong direction on how this product is meant to be used, please correct me as I'm kinda stumped on this.

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
user125264
  • 1,809
  • 2
  • 27
  • 54

1 Answers1

0

Chances are, that you are using multiupload variant of Uploadcare widget and it returns group's UUID to the input field.

To get UUIDs of individual files in a group you have to options:

  • request group info via REST API, it will contain all files' info
  • use JS API to get files' UUIDs upon upload is complete:

    var multipleWidget = uploadcare.MultipleWidget("[role=uploadcare-uploader]");
    $ = uploadcare.jQuery; // skip this if you already have jQuery on the page
    multipleWidget.onChange(function(group) {
      if (group) {
        group; // group object
        group.files(); // array of file objects
        $.when.apply(null, group.files()).then(function() {
          arguments; // array of individual file infos
          $.each(arguments, function() {
            console.log(this.cdnUrl); // URL of uploaded file
            console.log(this.uuid);   // UUID of uploaded file
          });
        });
      }
    });
    
Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31