我正在尝试使用Filestack(Filepicker)V3上传多个文件并获取文件名,URL和mimetype。因此,根据此新发行版的Filestack文档,并按照a similar question before,我有以下内容:
var client = filestack.init('myapikey');
client.pick({
accept: 'image/*',
fromSources: ['local_file_system','googledrive','gmail','facebook','dropbox','onedrive','webcam'],
maxFiles: 5,
imageMax: [1024, 1024]
}).then(function(Blobs) {
console.log(JSON.stringify(Blobs));
var result = "";
for(var i=0; i<Blobs.length; i++){
result+=Blobs[i].filename + " : " + Blobs[i].url + " : " + Blobs[i].mimetype;
}
alert(result);
});
例如,我上传了2个文件,在控制台中,结果如下:
{"filesUploaded":[{"filename":"diploma1.jpg","handle":"1e3CkeZQaeokzS9TpcJM","mimetype":"image/jpeg","originalPath":"diploma1.jpg","size":258169,"source":"local_file_system","url":"https://cdn.filestackcontent.com/1e3CkeZQaeokzS9TpcJM","originalFile":{"customName":"diploma1.jpg"},"status":"Stored"},{"filename":"diploma2.jpg","handle":"kOejeHySTSG0TuSJWWlh","mimetype":"image/jpeg","originalPath":"diploma2.jpg","size":31072,"source":"local_file_system","url":"https://cdn.filestackcontent.com/kOejeHySTSG0TuSJWWlh","originalFile":{"customName":"diploma2.jpg"},"status":"Stored"}],"filesFailed":[]}
但是警报显示没有结果,我想要这样的警报结果:
diploma1.jpg : https://cdn.filestackcontent.com/1e3CkeZQaeokzS9TpcJM : image/jpeg
diploma2.jpg : https://cdn.filestackcontent.com/kOejeHySTSG0TuSJWWlh : image/jpeg
我需要一些帮助。
最佳答案
我一直在寻找有关结果控制台的信息,并根据此question修改了代码以最终得到结果:
var client = filestack.init('myapikey');
client.pick({
accept: 'image/*',
fromSources: ['local_file_system','googledrive','gmail','facebook','dropbox','onedrive','webcam'],
maxFiles: 5,
imageMax: [1024, 1024]
}).then(function(Blobs) {
console.log(JSON.stringify(Blobs));
var result = JSON.parse(JSON.stringify(Blobs));
var res = "";
for(var i=0; i<result.filesUploaded.length; i++){
res+=result.filesUploaded[i].filename + " : " + result.filesUploaded[i].url + " : " + result.filesUploaded[i].mimetype + "\n";
}
alert(res);
});
:)
关于javascript - 在Filestack v3中未获取JSON的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45512627/