2 回答

TA貢獻(xiàn)1779條經(jīng)驗 獲得超6個贊
您沒有在此代碼中的任何位置給出值,這與您調(diào)用時的事實相匹配(如錯誤消息所述,您無法將未定義的值寫入數(shù)據(jù)庫)imgURLundefineditemsRef.push(clientObj)
看起來您正在嘗試將下載 URL 寫入數(shù)據(jù)庫。為此,我將密切關(guān)注文檔中的示例。但根據(jù)您當(dāng)前的代碼,它應(yīng)該是這樣的:
let itemsRef = firebase.database().ref('testimonials');
let imgFile = this.state.currentImg;
let imageRef;
let imgURL;
if (imgFile){
let ref = firebase.storage().ref("testimonialPics/"+imgFile.name);
let task = ref.put(imgFile);
task.then(() => {
// this runs when the upload has completed
ref.getDownloadURL().then(function(downloadURL) {
// this runs when the download URL has been determined
let clientObj = {
name: this.state.currentName,
feedback: this.state.currentComments,
approved: false,
clientImg: downloadURL
}
itemsRef.push(clientObj);
this.setState({
currentName: "",
currentComments: "",
currentImg: null
})
})
})

TA貢獻(xiàn)1868條經(jīng)驗 獲得超4個贊
添加回答
舉報