【问题标题】:How to await the upload of file to Firebase Storage in Flutter?如何在 Flutter 中等待文件上传到 Firebase 存储?
【发布时间】:2019-05-03 14:53:50
【问题描述】:

我正在尝试使用以下代码将图像上传到 Flutter 中的 Firebase 存储。

StorageReference reference =
    FirebaseStorage.instance.ref().child("$fileId.jpg");
StorageUploadTask uploadTask = reference.putFile(_imageFile);

这似乎确实有效。但我需要找到一种方法,等待这个上传过程。鉴于reference.putFile(file) 不会返回未来,我该怎么办?

【问题讨论】:

    标签: firebase dart flutter firebase-storage


    【解决方案1】:

    我最终找到了解决方案,这里提到了:Flutter: Get FirebaseStorage Download URL & Upload Status

    https://stackoverflow.com/users/6618622/copsonroad 的回答

    我们可以使用这个:

    StorageUploadTask uploadTask = ref.putFile(avatarImageFile);
    StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
    String downloadUrl = await storageTaskSnapshot.ref.getDownloadURL();
    

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 2019-02-10
      • 2021-09-19
      • 2021-07-03
      • 2021-10-28
      • 2020-04-30
      • 2021-05-11
      • 2018-12-21
      • 2019-01-26
      相关资源
      最近更新 更多