获取Firebase存储中的图像名称 [英] Get the names of the images in the firebase storage

查看:69
本文介绍了获取Firebase存储中的图像名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在按名称从Firebase下载图像.

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

 storageRef.child("NAME OF your IMAGE").getBytes(Long.MAX_VALUE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
                @Override
                public void onSuccess(byte[] bytes) {
                    // Use the bytes to display the image
                    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                    imageView.setImageBitmap(bitmap);
                } 

是否可以将存储在Firebase存储器中的图像的所有名称都保存到列表中.

Is it possible to get all the names of the images stored in firebase storage to a list.

推荐答案

否,您不能.您可以做的是在Firebase数据库中创建一个名为imageNames的新部分,每次将映像添加到Firebase Storage时,都应在该新节点下添加相应的核心映像名称,如下所示:

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

要获取所有这些名称,只需在此imageNames节点上附加一个侦听器,然后像这样从dataSnapshot对象获取所有这些名称:

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);

这篇关于获取Firebase存储中的图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆