Skip to content

Instantly share code, notes, and snippets.

@codeboy5
Created June 13, 2019 19:55
Show Gist options
  • Save codeboy5/86a7a7099b6d90420b7ea43454f466eb to your computer and use it in GitHub Desktop.
Save codeboy5/86a7a7099b6d90420b7ea43454f466eb to your computer and use it in GitHub Desktop.
Script To Fetch Images From Firebase Storage
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var storage = firebase.storage();
var storageRef = storage.ref();
//! List All Albums
storageRef
.listAll()
.then(result => {
result.prefixes.forEach(element => {
displayAlbum(storageRef.child(`${element.fullPath}`));
// console.log(element.fullPath);
});
})
.catch(err => console.log(err));
// List All Photos In That Album
function displayAlbum(albumRef) {
albumRef
.listAll()
.then(result => {
result.items.forEach(element => {
element
.getDownloadURL()
.then(url => console.log(url))
.catch(err => console.log("Error In Getting"));
});
})
.catch(err => console.log(err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment