Getting a list of files from Firebase Storage (title and URL):
jsx// Getting images from a folder in Firebase Storage var images = firebase.storage().ref().child(folder); // Getting the references of these images images.listAll().then( result => { if(result){ // Mapping the images references result.items.map( reference => { // Getting title let title = reference.name; // Getting downloadURL reference.getDownloadURL().then( downloadURL => { // This is a new object containing title and url let object = {title: title, url: downloadURL}; }); }); } }).catch( error => { // Handling errors });
If you don't want to list all the images from the folder, replace the listAll()
function by list({maxResults: nResults})
.
Example for 100 items:
jsx// Getting images from a folder in Firebase Storage var images = firebase.storage().ref().child(folder); // Getting the references of 100 images images.list( {maxResults: 100} ).then( result => { // ... });
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.