How to download entire folder from Firebase Storage?

27,056

Solution 1

There is no API in Firebase Storage to download all files in a folder. You will have to download the files one by one, or create a zip file that contains all the files.

As Lahiru's answer shows it can be accomplished with gsutils, but that's a server-side operation - not something you'd run in your client-side application.

Related:

Solution 2

You can use gsutil to download the whole storage bucket

gsutil -m cp -R gs://<bucket_name> .

Solution 3

Command gustil for Windows !!!

gsutil cp -r gs://<bucket_name>.appspot.com/OBJECT_NAME "D:\path"

Use Cloud tools for PowerShell

REF for install windows >> https://cloud.google.com/storage/docs/gsutil_install

Share:
27,056
isuru
Author by

isuru

By Day - Like to find new coding standards and best practices

Updated on July 09, 2022

Comments

  • isuru
    isuru almost 2 years

    I want to download an entire folder from Firebase storage. I can download single files using DownloadURL as follows, but it does not work for folders.

    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;
      }
    });
    

    How to download entire folder from Firebase?

  • isuru
    isuru over 7 years
    I cannot find the way to get all the files and create a zip file from above related links. Please give me some tips to find a way to create a zip file that contains all the files. Thanks for your response.
  • ismaestro
    ismaestro over 5 years
    easiest solution!
  • HartleySan
    HartleySan over 4 years
    This worked well. Installing gsutil was the most time-consuming part.
  • Lorence Cramwinckel
    Lorence Cramwinckel about 4 years
    Don't forget to enter the destination URL after the gsutil command like so: gsutil cp -r gs://<bucket_name>.appspot.com Downloads The destination URL must name a directory, bucket, or bucket subdirectory.
  • Xeaza
    Xeaza about 4 years
    One thing that tripped me up for a bit was I forgot to add the . at the end in the answer above. That . is important :)
  • Ritwik
    Ritwik about 4 years
    refer to this for installing gsutil
  • Swetabja Hazra
    Swetabja Hazra over 3 years
    Thanks, this saved my life. I accidentally deleted files which were only there in my firebase storage.
  • 151291
    151291 over 3 years
    But, this is system-level installation right? how to archive it via Node APIs?
  • Trake Vital
    Trake Vital over 3 years
    Btw in windows you should run the shell in administrator to not get Access Denied
  • Soorya
    Soorya over 3 years
    Appending folder name after the bucket url also works (if you want to download only one particular folder).
  • MorenoMdz
    MorenoMdz about 3 years
    Is it possible to run that from the backend Admin SDK?
  • RumbleFish
    RumbleFish about 2 years
    gsutil is also available for Mac, terminal command is same as above (change dest. path!)... cloud.google.com/storage/docs/gsutil_install#mac