How to get a list of all files in Cloud Storage in a Firebase app?

后端 未结 19 1066
傲寒
傲寒 2020-11-21 11:25

I\'m working on uploading images, everything works great, but I have 100 pictures and I would like to show all of them in my View, as I get the complete list of

19条回答
  •  眼角桃花
    2020-11-21 12:02

    To do this with JS

    You can append them directly to your div container, or you can push them to an array. The below shows you how to append them to your div.

    1) When you store your images in storage create a reference to the image in your firebase database with the following structure

    /images/(imageName){
       description: "" , 
       imageSrc : (imageSource) 
    }
    

    2) When you load you document pull all your image source URLs from the database rather than the storage with the following code

    $(document).ready(function(){
    
    var query = firebase.database().ref('images/').orderByKey();
    query.once("value").then(function(snapshot){
    
        snapshot.forEach(function(childSnapshot){
    
            var imageName = childSnapshot.key;
            var childData = childSnapshot.val();
            var imageSource = childData.url;
    
            $('#imageGallery').append("
    "); }) }) });

提交回复
热议问题