【问题标题】:Can't get a proper URL when Image from Storage Firebase is linked to CloudFirestore当来自 Storage Firebase 的图像链接到 CloudFirestore 时,无法获取正确的 URL
【发布时间】:2021-03-03 18:02:21
【问题描述】:

当图像从 Firebase 中的存储链接到 CloudFirestore 时,我无法在我的方法中获取有效 URL:

Future uploadImage(BuildContext context) async {
    String fileName = basename(_imageFile.path);
    Reference firebaseStorageRef =
        FirebaseStorage.instance.ref().child('ifprofile/$fileName');
    UploadTask uploadTask = firebaseStorageRef.putFile(_imageFile);
    TaskSnapshot taskSnapshot = await uploadTask.whenComplete(() {
      var firebaseUser = FirebaseAuth.instance.currentUser;
      FirebaseFirestore.instance.collection('/userProfile').add({
        "imageUrl": _imageFile.path,
       
      });
      FirebaseFirestore.instance
          .collection('/influencerUser')
          .doc(firebaseUser.uid)
          .update({
// All fields you want to update in a document
        'imageUrl': IfUserProfile.imageUrl,
     
      });
      // Finish to Link images to Cloud Firestore
    });
    taskSnapshot.ref
        .getDownloadURL()
        .then((value) => print("Image uploaded: $value"));
  }

进入云火库我得到这样的 URL:

/data/user/0/it.test.testapp/cache/image_picker5217031945896769637.jpg

请问有什么意见吗?

【问题讨论】:

标签: flutter google-cloud-firestore firebase-storage


【解决方案1】:

尝试修改你的代码a但是像这样

final url = await taskSnapshot.ref
    .getDownloadURL();

然后将该 URL 放入您的 Firestore 数据库中

这里有一些代码

final storageRef = FirebaseStorage.instance.ref('$folderName/$imagename');
final uploadTaskSnapshot = await storageRef.put(image).future;

final imageUri = await uploadTaskSnapshot.ref.getDownloadURL();

【讨论】:

  • 你的意思是“然后把那个url放到你的firestore db中”
  • 您需要等待该特定任务完成
猜你喜欢
  • 2021-03-04
  • 2017-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-08-27
  • 2017-12-03
  • 2018-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多