从Firebase存储中检索文件 [英] Retrieve file from firebase storage
问题描述
我敢打赌,这是非常琐碎的事情,但是即使是文档高级人士也对此一无所知.我不必提到,在Google搜索中编写有关Firebase的任何内容都会返回与JS/WEB不相关的主题,而在大多数情况下与android相关...
I bet it's something very trivial, but even the docs arent clear about this. I don't have to mention that writing anything about firebase in google search returns topics that are related not with JS/WEB but with android in most cases...
这种情况是我有一个保存文件夹... images
.我想在进入我的网站时找回它.我的尝试:
The case is that I have a storage folder images
that holds... images. I would like to retrieve it when entering my site. My try:
componentDidMount() {
const images = firebase.storage().ref().child('companyImages');
const image = images.child('image1'); <---------------- // file name is image1
image.on('value', (snap) => this.setState({ img: snap.val() }));
}
但是它不能像我想的那样工作.如您所见,我想将此图片存储在状态中,然后在网站的某些部分中显示.
However it doesnt work as I suppose it to do. As u can see I would like to store this image in state and then display in some part of my site.
期待任何提示等. 谢谢你:)
Looking forward for any hints etc. Thank u :)
推荐答案
on("value"
方法混淆了数据库SDK .
There is no method on()
in the Firebase Storage SDK for the Web. You're probably confusing it with the on("value"
method in the Firebase Database SDK.
要从Firebase网络应用中的Cloud Storage中下载数据,您获取文件的下载URL ,然后使用该文件(通常在您的HTML中)来获取数据.
To download data from Cloud Storage in your Firebase web app, you get the download URL for the file and then use that (typically in your HTML) to get the data.
componentDidMount() {
const images = firebase.storage().ref().child('companyImages');
const image = images.child('image1');
image.getDownloadURL().then((url) => { this.setState({ img: url }));
}
这篇关于从Firebase存储中检索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!