我需要循环访问StorageReference的所有子级。我怎样才能做到这一点?文档和stackoverflow都没有提到这一点。请帮帮我。
您可以按此处所述使用Google Cloud Storage的List API 。
一种使用方式listAll()
:
StorageReference listRef = storage.getReference().child("files/uid");
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.
}
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!
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句