我怎么能得到文件夹名称列表在Firebase存储Android?

3zwtqj6y  于 2023-06-20  发布在  Android
关注(0)|答案(3)|浏览(102)

如何获取所有文件夹文件/,R52 H50 TN 40 F/,R58 H42 X2 DCE/...

mzsu5hc0

mzsu5hc01#

有可能确保在build.gradle文件中有以下依赖项:

dependencies {
    ...
    implementation 'com.google.firebase:firebase-storage:19.1.1' // or later
}

下面是如何遍历目录列表及其条目:

listRef = FirebaseStorage.getInstance().getReference("/");             

listRef.listAll()                                                      
    .addOnSuccessListener(new OnSuccessListener<ListResult>() {        
        @Override                                                      
        public void onSuccess(ListResult listResult) {                 

            Log.d(TAG, listRef.getName());                             
            for (StorageReference prefix : listResult.getPrefixes()) { 
                Log.d(TAG, prefix.getName());                          
                // This will give you a folder name                    
                // You may call listAll() recursively on them.         
            }                                                          

            for (StorageReference item : listResult.getItems()) {      
                // All the items under listRef.                        
            }                                                          
        }                                                              
    })                                                                 
    .addOnFailureListener(new OnFailureListener() {                    
        @Override                                                      
        public void onFailure(@NonNull Exception e) {                  
            // Uh-oh, an error occurred!                               
        }                                                              
    });
ne5o7dgx

ne5o7dgx2#

使用firebase client api无法获取所有文件夹的列表
但是您可以合并Firebase FunctionsCloud Storage bucket API
1.创建一个firebase函数(documentation)
1.使用Firebase Bucket getFiles函数

oxiaedzo

oxiaedzo3#

可以As example shown here
第一步:添加Firebase存储依赖项

dependencies {
    ...
    implementation 'com.google.firebase:firebase-storage:19.1.1'
}

第二步:

storageReference=FirebaseStorage.getInstance().getReference("folders");
    storageReference.listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
        @Override
        public void onSuccess(ListResult listResult) {
            Log.d("Get List Ref",storageReference.getName());
            for(StorageReference prefix:listResult.getPrefixes())
            {
                Log.d("prefix",prefix.getName());
                FoldersYear.add(new FolderClass(prefix.getName()));
                Log.d("folder", String.valueOf(FoldersYear));
            }
           
      
        }

    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d("failure","failure");
        }
    });

构建您的项目并享受

相关问题