1

I am working on a school project and have elected to use Firebase as a storage option for uploading/downloading files via an app that I am developing. I would like to be able to display to the user a list of all the files within a specific folder, and also give that user the ability to upload files. However, it seems that the only way to access information within the firebase storage, is to, as the developer, know what the file is rather than find files and display them dynamically. I hope I am making sense with this.

Basically, I would like my app to access the firebase storage, go to a specified folder, and then create a bunch of image-buttons in a viewgroup based off of what is in the folder without having to know before hand what to expect.

Would this be possible via metadata? As in, when ever a new file/folder is created within this parent folder, could I also programmatically update that parent folder's metadata to say, "hey there are these specific files within this folder?"

2 Answers 2

3
var storage = firebase.storage();
    
// Create a storage reference from our storage service
 var storageRef = storage.ref();
        // Create a child reference
        var imagesRef = storageRef.child('yourMainFolder');
    
        // Find all the prefixes and items.
        imagesRef.listAll()
            .then((res) => {
    
                res.items.forEach((itemRef) => {
    
                    itemRef.getDownloadURL().then(function (url) {
                        console.log(url)
                    }).catch(function (error) {
                        // Handle any errors
                    });
                });
                res.prefixes.forEach((folderRef) => {
                    console.log("folder", folderRef._delegate._location.path_.split('/')[1])// In my case:)
    
                });
            }).catch((error) => {
                // Uh-oh, an error occurred!
            });
1

Currently there is no API in Firebase Storage to list all files in a folder.

What you can do is maintain a database of metadata information (such as file names and folder names) somewhere else.

Firebase Realtime Database would be a good choice for this task.

Not the answer you're looking for? Browse other questions tagged or ask your own question.