看過這個鏈接How to Upload image to firebase storage and save reference in the database in single transaction?,下面推薦的,softauthor 和其他一些網站來找出我做錯了什么,但沒有一個有效。我正在嘗試將影像發布到存盤,然后更新 RTDB 和 Firestore 中的鏈接。這是片段,我做錯了什么?(403 錯誤) 物件 { 代碼_:“存盤/未找到物件”
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);
});
});
});
uj5u.com熱心網友回復:
您需要等到檔案完全上傳后才能請求其下載 URL。
storageRef.put(file).then(() => {
firebase.storage().ref("users").child(user.uid).getDownloadURL()
.then((downloadURL) => {
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444496.html
標籤:javascript 火力基地 谷歌云存储 firebase-存储
