我有一个启用了多个上传的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?
答案 0 :(得分: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
});
});
}
});
您可以在docs
中找到更多详情