【问题标题】:How can I add a photoUrl to the current user?如何将 photoUrl 添加到当前用户?
【发布时间】:2021-01-12 19:32:10
【问题描述】:

在我的应用程序中,我选择了带有图像选择器 dart 包 (pub.dev link) 的图像。然后我将此图像上传到云存储。我也可以从数据库中获取 url,但是如何将此 url 作为 photoUrl 添加到当前用户?如何更新 firebase 用户?

图像选择器代码:

  getImage(BuildContext context) async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    if (image != null) {
      cropImage(image);
      _showDialog(context);
    }
    setState(() {
      _image = image;
      print("Image Path $_image");
    });
  }

上传代码:

  uploadPic(BuildContext context) async {
    String fileName = basename(_image.path);
    StorageReference firebaseStorageRef =
        FirebaseStorage.instance.ref().child("profilbilder/" + fileName);
    StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
    StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;

    // Photo URL
    var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
    String url = dowurl;
    setState(() {
      print("Profile Picture uploaded");
    });
  }

【问题讨论】:

标签: firebase flutter dart firebase-storage


【解决方案1】:

您可以使用 FirebaseUser 对象来存储用户个人资料照片的网址。

参考这里:Manage users

还有Firebase getUrl

【讨论】:

    猜你喜欢
    • 2022-10-04
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    相关资源
    最近更新 更多