第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

火庫存儲不允許我檢索圖像 URL

火庫存儲不允許我檢索圖像 URL

呼啦一陣風(fēng) 2022-09-23 16:55:19
我已成功將文件上傳到火庫存儲。但是,當(dāng)我包含狀態(tài)已更改的 .on 函數(shù)時,控制臺會引發(fā)以下錯誤:錯誤:引用.push 失?。旱谝粋€參數(shù)在屬性“見證.clientImg”中包含未定義的參數(shù)我正在嘗試重新獲取圖像URL并將其放在變量中。我的代碼如下所示,任何人都可以提供幫助嗎?  let itemsRef = firebase.database().ref('testimonials');  let imgFile = this.state.currentImg;  let imageRef;  let imgURL;  if (imgFile){   imageRef = firebase.storage().ref("testimonialPics/"+imgFile.name).put(imgFile);   imageRef.on('state_changed', (snapshot)=>{    console.log(snapshot);   })  let clientObj = {    name: this.state.currentName,    feedback: this.state.currentComments,    approved: false,    clientImg: imgURL  }  itemsRef.push(clientObj);  console.log(clientObj);  this.setState({    currentName: "",    currentComments: "",    currentImg: null  })
查看完整描述

2 回答

?
哆啦的時光機(jī)

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

      })

    })

  })


查看完整回答
反對 回復(fù) 2022-09-23
?
MYYA

TA貢獻(xiàn)1868條經(jīng)驗 獲得超4個贊

https://firebase.google.com/docs/storage/web/download-files#download_data_via_url試試這個。我認(rèn)為你聽錯了聽眾。


查看完整回答
反對 回復(fù) 2022-09-23
  • 2 回答
  • 0 關(guān)注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號