我想从Firebase存储中下载整个文件夹。我可以使用DownloadURL
下载单个文件,如下所示,但它不适用于文件夹。
var storageRef = firebase.storage().ref();
// Create a reference to the file we want to download
var starsRef = storageRef.child(path);
// Get the download URL
starsRef.getDownloadURL().then(function(url) {
// Insert url into an <img> tag to "download"
ImageUrl = url;
console.log(ImageUrl);
}).catch(function(error) {
switch (error.code) {
case 'storage/object_not_found':
// File doesn't exist
break;
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect the server response
break;
}
});
如何从Firebase下载整个文件夹?
6条答案
按热度按时间zf9nrax11#
您可以使用gsutil下载整个存储桶
8wtpewkr2#
Firebase Storage中没有用于下载文件夹中所有文件的API。您必须逐一下载文件,或创建包含所有文件的zip文件。
正如Lahiru's answer所示,它可以用
gsutils
来完成,但这是一个服务器端操作,而不是在客户端应用程序中运行的操作。相关信息:
mm5n2pyu3#
命令gustil用于Windows!!!
为PowerShell使用云工具
安装windows >> https://cloud.google.com/storage/docs/gsutil_install的参考
uwopmtnx4#
您可以通过创建一个zip文件来下载该文件夹。
下面是一个示例函数:
kse8i1jr5#
有关在zip文件中包含JavaScript的递归解决方案,请参见下面的示例。您将示例化一个jszip对象,等待来自压缩文件并遍历目录的函数的promise,然后保存压缩文件。如果内容是一个文件(“item”),它将被压缩到jszip对象中。如果它是一个文件夹(“prefix”),函数将再次调用,并使用新的子路径,传入相同的jszip对象。为了进一步改进,如果您的内容对于
listAll
来说太多,您可能希望使用list
和分页来获取内容,因为listAll
限制了检索。h9vpoimq6#
根据上面的建议,我编写了.html脚本。
1.填写证件
1.填写文件夹名称
1.保存
1.用浏览器打开.html文件
1.很高兴