简体   繁体   English

所需参考处不存在 object

[英]No object exists at the desired reference

I am trying to get an image from the storage and use the url for a default profile picture but i am getting this error.我正在尝试从存储中获取图像并使用 url 作为默认配置文件图片,但出现此错误。

firebase_storage/object-not-found No object exists at the desired reference. firebase_storage/object-not-found 所需参考处不存在 object。

This is my code.这是我的代码。

void authenticateStudent() async {
    User? currentStudent;
    final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
    await firebaseAuth
        .createUserWithEmailAndPassword(
      email: umailController.text.trim(),
      password: passwordController.text.trim(),
    )
        .then((auth) {
      currentStudent = auth.user;
    }).catchError((onError) {
      print(onError);
    });
    if (currentStudent != null) { 
FirebaseStorage.instance
          .ref()
          .child('profile')
          .getDownloadURL()
          .then((url) {
        imageUrl = url;
      });
saveDataToFirestore(currentStudent!).then((value) {
        Navigator.pop(context);
        print("User added successfully");
      });
    }
  }

Future saveDataToFirestore(User currentStudent) async {
    FirebaseFirestore.instance
        .collection("students")
        .doc(currentStudent.uid)
        .set({
      "studentUID": currentStudent.uid,
      "fname": fnameController.text.trim(),
      "lname": lnameController.text.trim(),
      "Mobile": phoneController.text.trim(),
      "Program": selectedProgram,
      "student_id": studentidController.text.trim(),
      "cohort": selectedCohort,
      "umail": currentStudent.email,
      "profilepicture": imageUrl,
      "active": active,
      "status": status
    });
  }

The database is structured like this数据库的结构是这样的

This is my code.这是我的代码。

void authenticateStudent() async {
    User? currentStudent;
    final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
    await firebaseAuth
        .createUserWithEmailAndPassword(
      email: umailController.text.trim(),
      password: passwordController.text.trim(),
    )
        .then((auth) {
      currentStudent = auth.user;
    }).catchError((onError) {
      print(onError);
    });
    if (currentStudent != null) { 
FirebaseStorage.instance
          .ref()
          .child('profile')
          .getDownloadURL()
          .then((url) {
        imageUrl = url;
      });
saveDataToFirestore(currentStudent!).then((value) {
        Navigator.pop(context);
        print("User added successfully");
      });
    }
  }

Future saveDataToFirestore(User currentStudent) async {
    FirebaseFirestore.instance
        .collection("students")
        .doc(currentStudent.uid)
        .set({
      "studentUID": currentStudent.uid,
      "fname": fnameController.text.trim(),
      "lname": lnameController.text.trim(),
      "Mobile": phoneController.text.trim(),
      "Program": selectedProgram,
      "student_id": studentidController.text.trim(),
      "cohort": selectedCohort,
      "umail": currentStudent.email,
      "profilepicture": imageUrl,
      "active": active,
      "status": status
    });
  }

The database is structured like this数据库的结构是这样的在此处输入图像描述

Your code says:你的代码说:

FirebaseStorage.instance
      .ref()
      .child('profile')
      .getDownloadURL()

But in the screenshot, the file is called profile.png .但在屏幕截图中,该文件名为profile.png The path must match completely and exactly, so:路径必须完全准确匹配,因此:

FirebaseStorage.instance
      .ref()
      .child('profile.png')
      .getDownloadURL()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: 'Reference' object 在 java 脚本中不可迭代 - TypeError: 'Reference' object is not iterable in java script 尝试在空对象引用上调用虚拟方法“…………” - Attempt to invoke virtual method '.........' on a null object reference Android studio null object 参考错误 - Android studio null object reference error AWS CDK 解析错误:无法使用循环引用解析 object 树 - AWS CDK Resolution error: Unable to resolve object tree with circular reference 尝试在 android studio firebase mainactivity 中的空对象引用上调用虚方法 boolean java.lang.String.equals(java.lang.Object) - Attempt to invoke virtual method boolean java.lang.String.equals(java.lang.Object) on a null object reference in android studio firebase mainactivity Select 与 GORM 存在 - Select exists with GORM Flutter Firebase 已经存在 - Flutter Firebase already exists Firebase Stripe Extension: No such payment_intent, 类似 object 存在于 live mode 中,但是使用了测试模式 key 来发出这个请求 - Firebase Stripe Extension: No such payment_intent, a similar object exists in live mode, but a test mode key was used to make this request 客户端无权访问 Firebase 中的所需数据 - Client doesn't have permission to access the desired data in Firebase Firebase 客户端无权访问所需数据 - Firebase Client doesn't have permission to access the desired data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM