Get list of images from Firebase Store

送分小仙女□ 提交于 2019-12-13 09:38:22

问题


I want to get list of images which I uploaded manually in web Firebase console. Is there any way I can get list of all files without using FirebaseRecyclerAdapter?


回答1:


There is no existing method to extract the list of file name you have saved in Firestore. Instead you have to use some workaround to manually create a list. For example, maintaining a list of file and URL inside Firebase database.

One possible solution is to write a trigger using cloud functions, listening to the changes made to Firebase Storage.(as this time you are doing the upload directly through console, you have to write a trigger and host it in cloud function). Upon there is insertion/ removal/ modification in the attachment list, update the dummy file entries inside the firebase database. When you are trying to extract the list of file/ url information, retrieve them from database but not storage.

You may refer to below document for more information: https://firebase.google.com/docs/functions/gcp-storage-events?hl=zh-cn

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




回答2:


There is no any functionality which can directly fetch your image from firebase storage so first of all, you have to create a database and in that add one field of Imageurl or something like that and then fetch that data or image from the URL using query. For the query build, I already mention code below use that.

 mDatabase = FirebaseDatabase.getInstance().getReference();
    Query query = mDatabase.child("DatabaseName").orderByChild("ImageUrl");
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                // dataSnapshot is the "issue" node with all children with id 0
                for (DataSnapshot issue : dataSnapshot.getChildren()) {
                    // do something with the individual "issues"
                    try {
                        imgeListModel.add(issue.getValue(ImageListModel.class));
                        Log.e("Get Data", issue.getValue(ImageListModel.class).toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
           databaseError.toException();
        }
    });


来源:https://stackoverflow.com/questions/49726579/get-list-of-images-from-firebase-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!