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.
JavaScript
x
31
31
1
var storageRef = firebase.storage().ref();
2
3
// Create a reference to the file we want to download
4
var starsRef = storageRef.child(path);
5
6
// Get the download URL
7
starsRef.getDownloadURL().then(function(url) {
8
// Insert url into an <img> tag to "download"
9
ImageUrl = url;
10
11
console.log(ImageUrl);
12
}).catch(function(error) {
13
switch (error.code) {
14
case 'storage/object_not_found':
15
// File doesn't exist
16
break;
17
18
case 'storage/unauthorized':
19
// User doesn't have permission to access the object
20
break;
21
22
case 'storage/canceled':
23
// User canceled the upload
24
break;
25
26
case 'storage/unknown':
27
// Unknown error occurred, inspect the server response
28
break;
29
}
30
});
31
How to download entire folder from Firebase?
Advertisement
Answer
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: