在js中将多个文件上传到Firebase存储后如何获取url数组 [英] how to get url array after uploading multiple file to firebase storage in js
本文介绍了在js中将多个文件上传到Firebase存储后如何获取url数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将多个文件上传到Firebase存储后如何获取url数组.我正在使用下面的代码,但它返回元数据数组.
how to get url array after uploading multiple files to firebase storage. i'm using the below code but it return metadatas array.
firebase.storage().ref().constructor.prototype.putFiles = function(files) {
var ref = this;
return Promise.all(files.map(function(file) {
return ref.child(file.name).put(file);
}));
}
// use it!
firebase.storage().ref().putFiles(files).then(function(metadatas) {
// Get an array of file metadata
}).catch(function(error) {
// If any task fails, handle this
});
推荐答案
最简单的方法是在上传每个文件后返回元数据的下载URL :
The simplest way is to return the download URL instead of the metadata after uploading each file:
return Promise.all(files.map(function(file) {
return ref.child(file.name).put(file).then(function() {
return ref.child(file.name).getDownloadURL();
})
}));
这篇关于在js中将多个文件上传到Firebase存储后如何获取url数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文