我试图将所有用户的个人资料照片存储在实时数据库中,但我遇到了一个问题。
当尝试上载带有此代码的PhotoUrl时,会出现此错误。
代码:
var user = firebase.auth().currentUser;
user.updateProfile({
// Here, "name" and "imgUrl" are parameters of parent function.
// I don't think this is the reason, but if it helps,
// "imgUrl" always come from a <img> src.
displayName: name,
photoUrl: imgUrl
}).then(function(){
// Here is where I try to upload all to the database
firebase.database().ref("/Usuarios/" + user.uid).set({
"email": email,
"name": name,
"photoUri": user.photoUrl, // This is where I think the problem originates.
"uid": user.uid // This calls user again, and it works perfectly.
});
});
Uncaught Error: Firebase.set failed: First argument contains undefined in property 'Usuarios.kD1tD1NAmsaGiW0zj6lFz9GDWro1.photoUri'.
当我这么做的时候
警报(user.photoUrl)
我首先想到的是它不能保存在数据库中,因为它不是一个字符串,所以我尝试从中调用toString(),但我做不到。
toString()错误:
Uncaught TypeError: Cannot read property 'toString' of undefined
提前谢谢。