提问者:小点点

Firebase存储不允许我检索图像URL


我正在成功地将文件上传到firebase存储库。

但是,当我将。on函数包含在statechanged中时,控制台会抛出以下错误:

错误:Reference.Push失败:第一个参数在属性“Testimonials.ClientImg”中包含未定义的内容

我正在尝试检索图像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
  })

共1个答案

匿名用户

https://firebase.google.com/docs/storage/web/download-files#download_data_via_url试一下。 我想你听错人了。