【问题标题】:How do i get the image download URL in database in Flutter如何在 Flutter 中获取数据库中的图像下载 URL
【发布时间】:2020-10-27 14:41:11
【问题描述】:

我想获取图片下载链接并将其存储在 Firestore 数据库中。下面是上传图片到 Firebase 存储的功能,如果功能错误,请解释原因并给我写一个功能?

File _image1;
Future uploadPic() async {
    StorageReference reference = storage.ref().child('image');
    StorageUploadTask uploadTask = reference.putFile(_image1);
    StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
    String url = await taskSnapshot.ref.getDownloadURL();
    imageUrl1 = url;
  }

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    在函数中添加返回以检索输出(url)

    File _image1;
    Future uploadPic() async {
        StorageReference reference = storage.ref().child('image');
        StorageUploadTask uploadTask = reference.putFile(_image1);
        StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
        String url = await taskSnapshot.ref.getDownloadURL();
        imageUrl1 = url;
        return url;
      }
    

    从这里你可以调用then函数,

    uploadPic().then((value)
                {
            DocumentReference docRef = 
            Firestore.instance.collection('collectionname').document(documentid);
                 docRef.setData({'pic' : value},merge:true)
                 });
    

    【讨论】:

    • 谢谢伙计。真的,你救了我。 @kingmort。我真的很感激
    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2020-04-20
    • 2018-06-02
    相关资源
    最近更新 更多