Get the names of the images in the firebase storage

后端 未结 1 1983
攒了一身酷
攒了一身酷 2021-01-07 15:00

Right now i am downloading the images from the firebase by its name..

 storageRef.child(\"NAME OF your IMAGE\").getBytes(Long.MAX_VALUE).addOnSuccessListener         


        
相关标签:
1条回答
  • 2021-01-07 15:45

    No, you cannot. What can you do inseatd is to create a new section in your Firebase database named imageNames and every time you add an image to Firebase Storage, add to coresponding image name under this new node like this:

    Firebase-root
       |
       --- imageNames
               |
               --- imageId1: ImaneName1
               |
               --- imageId2: ImaneName2
    

    To get all those names, just attach a listener on this imageNames node and get all those names from the dataSnapshot object like this:

    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference imageNamesRef = rootRef.child("imageNames");
    ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot ds : dataSnapshot.getChildren()) {
                String imageName = ds.getValue(String.class);
                Log.d("TAG", imageName);
            }
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {}
    };
    imageNamesRef.addListenerForSingleValueEvent(eventListener);
    
    0 讨论(0)
提交回复
热议问题