2 回答
TA贡献1779条经验 获得超6个赞
您没有在此代码中的任何位置给出值,这与您调用时的事实相匹配(如错误消息所述,您无法将未定义的值写入数据库)imgURLundefineditemsRef.push(clientObj)
看起来您正在尝试将下载 URL 写入数据库。为此,我将密切关注文档中的示例。但根据您当前的代码,它应该是这样的:
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贡献1868条经验 获得超4个赞
添加回答
举报