从Firebase存储中检索文件夹和文件

时间:2018-07-20 16:59:11

标签: android firebase firebase-storage

我在Firebase Storage中创建了一些文件夹,并将一些文件存储到了这些文件夹中。现在,我试图将这些文件夹作为ListView解析到我的应用程序中。我也想从那些文件夹中解析那些文件。 如果您对此有任何想法,请帮助我。 谢谢。

1. enter image description here

2. enter image description here

1 个答案:

答案 0 :(得分:0)

您需要知道从Cloud Storage for Firebase下载文件的路径或下载URL。无法从文件夹中获取所有文件。我建议上传任何文件后,将下载URL存储到Cloud Firestore之类的数据库中。当然,您不必使用Cloud Firestore。无论您将数据存储在哪里,都可以使用。我提供了一个获取下载URL的简单示例。如果您想了解有关在其中存储数据的更多信息,请参见上面的Firestore链接。

storageRef.child("CSE101/RNA.docx").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        // Got the download URL for "CSE101/RNA.docx"
        // add it to your database
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});