我正在尝试获取 Firebase 存储中目录内的子文件夹和文件的名称和 url。 但 listAll 总是会出现 onFailure
我尝试了以下代码:
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference listRef = storage.getReference();
listRef = listRef.child("Musics");
Log.d("hafiz", listRef.getName());
listRef.listAll()
.addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for (StorageReference prefix : listResult.getPrefixes()) {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
Log.d("hafiz", prefix.getName());
}
for (StorageReference item : listResult.getItems()) {
// All the items under listRef.
Log.d("hafizitem", item.getName());
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Uh-oh, an error occurred!
//
Log.d("jibon", e.getMessage());
}
});
我收到此错误:
发生未知错误,请检查HTTP结果代码和服务器响应的内部异常。
这是我的存储规则:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
将rules_version = '2'添加到规则中。例如这里
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}