简体   繁体   English

Firebase在“ downloadURL”上返回“ Undefined”

[英]Firebase return “Undefined” on “downloadURL”

I was just making a test with react and firebase (a simple app to upload image and, after the upload, show it on the page). 我只是用react和firebase(一个简单的应用程序来上传图像,然后在页面上显示出来)进行测试。 The uploas is always successful, but I cannot show the image because the "dowloadURL" is undefined. uploas总是成功的,但是由于“ dowloadURL”未定义,所以我无法显示图像。

Can someone help me? 有人能帮我吗?

Here is the React/Firebase-call code 这是React / Firebase调用代码

 handleUpload(e) { console.log('handelUpload'); const file = e.target.files[0]; const storageRef = firebase.storage().ref(`/fotos/${file.name}`); const task = storageRef.put(file); task.on( 'state_changed', snapshot => { let percentage = snapshot.bytesTransferred / snapshot.totalBytes * 100; this.setState({ uploadValue: percentage }); }, console.log, () => { const record = { photoURL: this.state.user.photoURL, displayName: this.state.user.displayName, image: task.snapshot.downloadURL }; const dbRef = firebase.database().ref('pictures'); const newPicture = dbRef.push(); newPicture.set(record); } ); } 

And this is the code where I put the image when upload 这是我上传时将图片放入其中的代码

  <FileUpload onUpload={this.handleUpload} /> {this.state.pictures.map(picture => <div> <hr/> <img src={picture.image} alt=""/> <br/> <img width="32" src={picture.photoURL} alt={picture.displayName}/> <br/> <span>{picture.displayName}</span> </div> ).reverse()} </div> 

Thank you! 谢谢!

In version 5 the downloadURL property was removed. 在版本5中, downloadURL属性已删除。 Please see: https://firebase.google.com/support/release-notes/js 请参阅: https : //firebase.google.com/support/release-notes/js

You should now use ref.getDownloadURL() (please note that this method returns a promise). 现在,您应该使用ref.getDownloadURL() (请注意,此方法返回一个ref.getDownloadURL() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM