【问题标题】:Flutter: How to get multi download url?Flutter:如何获取多个下载网址?
【发布时间】:2020-12-13 05:12:51
【问题描述】:
Future<List<dynamic>> uploadImage({List<File> images, String Key}) async {
    List<dynamic> imagesUrls = [];

    images.asMap().forEach((index, image) async {
      final StorageReference storageReference = FirebaseStorage().ref().child(_getImagePathByHereKey(Key, index: index));
      final StorageUploadTask uploadTask = storageReference.putFile(image);
    });

    return imagesUrls;
  }

我想获取下载地址并将其发送到imagesUrls。但是imagesUrls 是空的。如何获取下载地址?

【问题讨论】:

    标签: firebase flutter firebase-storage


    【解决方案1】:

    https://pub.dev/documentation/firebase/latest/firebase/StorageReference-class.html 有一个名为 getDownloadUrl() 的方法返回一个 Future。我假设这就是你要找的。我想你是这样使用它的:

    List<dynamic> imagesUrls = images.asMap().entries.map((entry) async {
          final StorageReference storageReference = FirebaseStorage().ref().child(_getImagePathByHereKey(Key, index: entry.key));
          final StorageUploadTask uploadTask = storageReference.putFile(entry.value);
          return await storageReference.getDownloadUrl();
        }).toList();
    
        return imagesUrls;
    

    我认为 entry.map 不能采用异步方法,所以你可能想使用流。认为你是从这里得到的。

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 2017-05-17
      相关资源
      最近更新 更多