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

后端 未结 19 1067
傲寒
傲寒 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:12

    So I had a project that required downloading assets from firebase storage, so I had to solve this problem myself. Here is How :

    1- First, make a model data for example class Choice{}, In that class defines a String variable called image Name so it will be like that

    class Choice {
        .....
        String imageName;
    }
    

    2- from a database/firebase database, go and hardcode the image names to the objects, so if you have image name called Apple.png, create the object to be

    Choice myChoice = new Choice(...,....,"Apple.png");
    

    3- Now, get the link for the assets in your firebase storage which will be something like that

    gs://your-project-name.appspot.com/
    

    like this one

    4- finally, initialize your firebase storage reference and start getting the files by a loop like that

    storageRef = storage.getReferenceFromUrl(firebaseRefURL).child(imagePath);
    
    File localFile = File.createTempFile("images", "png");
    storageRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener() {
    
    @Override
    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
        //Dismiss Progress Dialog\\
    }
    

    5- that's it

提交回复
热议问题