如何从Firebase存储下载整个文件夹?

isu*_*uru 19 javascript firebase firebase-storage

我想从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;
    }
  });
Run Code Online (Sandbox Code Playgroud)

如何从Firebase下载整个文件夹?

Lah*_*ima 24

您可以使用gsutil下载整个存储桶

gsutil -m cp -R gs://<bucket_name> .
Run Code Online (Sandbox Code Playgroud)

  • 让我有点困惑的一件事是我忘记在上面的答案末尾添加“.”。那个“.”很重要:) (7认同)
  • 不要忘记在 gsutil 命令后输入目标 URL,如下所示: `gsutil cp -r gs://&lt;bucket_name&gt;.appspot.com Downloads` 目标 URL 必须指定目录、存储桶或存储桶子目录。 (5认同)
  • 最简单的解决方案! (2认同)
  • 请参阅[此](https://cloud.google.com/storage/docs/gsutil_install#debian-and-ubuntu)安装gsutil (2认同)

小智 6

Windows下的gustil命令!!!

gsutil cp -r gs://<bucket_name>.appspot.com/OBJECT_NAME "D:\path"
Run Code Online (Sandbox Code Playgroud)

使用适用于 PowerShell 的云工具

安装 Windows 的参考>> https://cloud.google.com/storage/docs/gsutil_install


Fra*_*len 5

Firebase存储中没有API可以下载文件夹中的所有文件。您将必须一个一个地下载文件,或者创建一个包含所有文件的zip文件。

有关: