首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >React Native Firebase -如何从firebase存储中检索图像并在图像组件中显示?

React Native Firebase -如何从firebase存储中检索图像并在图像组件中显示?
EN

Stack Overflow用户
提问于 2018-10-26 22:19:44
回答 2查看 12.1K关注 0票数 1

从firebase.storage().ref('asd')获取图像的引用后,如何在此处检索图像并将其分配给图像组件?

代码语言:javascript
运行
复制
const ref = firebase.storage().ref('path/to/image.jpg');

<Image
  source={?}
/>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-05 06:08:45

您可以在引用上调用getDownloadURL()来获取图像的URL,然后可以将其作为URI源传递给图像组件,例如:

代码语言:javascript
运行
复制
const ref = firebase.storage().ref('path/to/image.jpg');
const url = await ref.getDownloadURL();

// ... in your render

<Image
  source={{ uri: url }}
/>

文档:

v5:https://rnfirebase.io/docs/v5.x.x/storage/reference/Reference#getDownloadURL

v6:https://invertase.io/oss/react-native-firebase/v6/storage/reference/reference#getDownloadURL

票数 9
EN

Stack Overflow用户

发布于 2020-01-30 18:31:28

这可能有点晚了,但是,这对我来说很有效。我对存储提出了一个单独的请求,getDownloadURL()在rnfirebase v6中的putFile()上不可用。

代码语言:javascript
运行
复制
const ref = firebase.storage().ref("images/name.jpg");
ref.getDownloadURL()
.then(url => {console.log(url)})
.catch(e=>{console.log(e);})
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53010751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档