flutter - Flutter - 如何列出 Firebase 存储中的所有图像
问题描述
我需要列出 Firebase 存储中特定目录中的所有图像。此解决方案显示了 listAll() 的工作原理https://stackoverflow.com/a/58430817/13720706
但如果我使用这个:
void getFirebaseImageFolder() {
final StorageReference storageRef =
FirebaseStorage.instance.ref().child('Gallery').child('Images');
storageRef.listAll().then((result) {
print("result is $result");
});
}
我得到一个包含许多值的长字符串:
result is {prefixes: {}, pageToken: null, items: {2020-06-2816:15:51.669533_250x250.jpg: {bucket: xxxxxxxxxxx.appspot.com, path: /userStorage/xxxxxxxxxxx/k6ouUrjUhMXJjDButEtF/L8H5IVSVhUKPLaGFLBaK/3VfcLmjR8ojxzPCboM9U/thumbs/2020-06-2816:15:51.669533_250x250.jpg, name: 2020-06-2816:15:51.669533_250x250.jpg}, 2020-06-2816:14:31.223608_250x250.jpg: {bucket: xxxxxxxxxxx.appspot.com, path: /userStorage/xxxxxxxxxxx/k6ouUrjUhMXJjDButEtF/L8H5IVSVhUKPLaGFLBaK/3VfcLmjR8ojxzPCboM9U/thumbs/2020-06-2816:14:31.223608_250x250.jpg, name: 2020-06-2816:14:31.223608_250x250.jpg}}}
所以问题是我如何才能利用这些价值观?如何仅获取图像的路径?
我试过这个:result.items.path 但它不能识别这个命令。
有人知道如何列出图像吗?
谢谢
解决方案
使用此功能列出特定目录中所有照片的 URL。
Future<void> listPhotos() async {
firebase_storage.ListResult result = await firebase_storage
.FirebaseStorage.instance
.ref().child('Gallery').child('Images').listAll();
for (firebase_storage.Reference ref in result.items) {
String url = await firebase_storage.FirebaseStorage.instance
.ref(ref.fullPath)
.getDownloadURL();
print(url);
}
}
您可以点击此链接了解更多详情。
推荐阅读
- makefile - 告诉 make 目标将在子文件夹中
- velo - 在wix上使用中继器时如何从数据的延续中制作下一页?
- javascript - 打字稿验证器模式正则表达式在 Internet Explorer 中出现意外的量词错误,但在 Google Chrome 中有效
- mysql - 将 SQL 查询转换为 Hive 查询
- php - 如何获得大于零的最小值?
- c++ - 私人测试用例没有通过。这里有什么错误?
- go - 限制资源 Kubernetes 集群用于 Web 服务
- javascript - 邮递员:如何断言所有数组元素都存在于其他数组中?
- ios - iOS 13 上 UITextField 中的 URL 被修剪
- python - 使用 r2pipe 进行多处理