Search code examples
javascriptfirebasefirebase-realtime-databasefirebase-storage

How to retrieve all the names of file in Firebase folder


I am currently building a web app that uploads files in a folder in Firebase. Each time I upload a file in Firebase storage folder I also use Firebase database to store the file name and download URL. Is it possible to retrieve all files that are stored in the specific folder as an array so the user can choose which one he wants to download?


Solution

  • Since you are linking the url of the image in the database for example:

    Uploads
      pushid
         urlfile: url_here
         uploadedby: userx
      pushid
         urlfile: url_here
         uploadedby: usery
    

    you can change the database as you want

    You can then do this:

    firebase.database().ref("Uploads").orderByChild('urlfile').on('value', function(snapshot) {
    snapshot.forEach(function(child) {
    var files=child.val().urlfile;
     )};
    )};
    

    this way you can retrieve the urls from the database and then store them in an array using push()