【问题标题】:Flutter - How to list all images from Firebase StorageFlutter - 如何列出 Firebase 存储中的所有图像
【发布时间】:2020-10-30 05:12:34
【问题描述】:

我需要列出 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 但是它不识别这个命令。

有人知道如何列出图片吗?

谢谢

【问题讨论】:

    标签: flutter firebase-storage


    【解决方案1】:

    使用此功能列出特定目录中所有照片的 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);
        }
      }
    

    您可以关注this link了解更多详情。

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2020-10-24
      • 2020-10-29
      • 2021-12-23
      • 1970-01-01
      • 2022-10-14
      • 2017-07-17
      • 2021-10-14
      • 2019-12-17
      相关资源
      最近更新 更多