看了这个链接如何在单个事务中将图像上传到 firebase 存储并在数据库中保存引用? https://stackoverflow.com/questions/47012372/how-to-upload-image-to-firebase-storage-and-save-reference-in-the-database-in-si、下面推荐的网站、softauthor 和其他一些网站来找出我做错了什么,但没有一个起作用。我正在尝试将图像发布到存储,然后更新 RTDB 和 Firestore 中的链接。这是片段,我做错了什么? (403错误)+对象{code_:“存储/未找到对象”
updatePfp.addEventListener("change", (e) => {
file = e.target.files[0];
var storageRef = firebase.storage().ref("users").child(user.uid);
storageRef.put(file)
firebase.storage().ref("users").child(user.uid).getDownloadURL()
.then(imgUrl => {
var downloadURL = imgUrl;
db.collection("userInfo")
.doc(user.uid)
.update({
downloadURL: downloadURL,
})
.then(function() {
alert("saved");
})
.catch(function(error) {
alert(error);
});
});
});
您需要等到文件完全上传后才能请求其下载 URL。
storageRef.put(file).then(() => {
firebase.storage().ref("users").child(user.uid).getDownloadURL()
.then((downloadURL) => {
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)