2

我有一个启用了多个上传的 Uploadcare 小部件。当我调用该函数uploadcare.Widget("[role=uploadcare-uploader]")时,它会引发异常

我的输入:

<input type="hidden" 
       id="uploadcare-uploader"
       data-multiple 
       data-images-only
       data-multiple-max="15"
       role="uploadcare-uploader" 
       name="my_file" />

另外,如何在 JavaScript 中获取用户上传的图像的 UUID?

4

1 回答 1

1

这将不起作用,因为您在应该使用多个文件时尝试初始化单个文件小部件。尝试这个:

var multipleWidget = uploadcare.MultipleWidget("[role=uploadcare-uploader]");

至于获取 UUID:

$ = 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
      });
    });
  }
});

您可以在文档中找到更多详细信息

于 2014-07-10T11:26:28.517 回答