React Native Firebase - 如何从 firebase 存储中检索图像并在图像组件中显示?
React Native Firebase - How to retrieve images from firebase storage and display in Image component?
从 firebase.storage().ref('asd') 获取图像的 ref 后,如何在此处检索图像并分配给图像组件?
const ref = firebase.storage().ref('path/to/image.jpg');
<Image
source={?}
/>
您可以在引用上调用 getDownloadURL()
以获得图像的 URL,然后可以将其作为 URI 源传递给图像组件,例如:
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
这可能晚了,但对我有用。我对存储提出了单独的请求,getDownloadURL() 在 rnfirebase v6 中的 putFile() 上不可用。
const ref = firebase.storage().ref("images/name.jpg");
ref.getDownloadURL()
.then(url => {console.log(url)})
.catch(e=>{console.log(e);})
从 firebase.storage().ref('asd') 获取图像的 ref 后,如何在此处检索图像并分配给图像组件?
const ref = firebase.storage().ref('path/to/image.jpg');
<Image
source={?}
/>
您可以在引用上调用 getDownloadURL()
以获得图像的 URL,然后可以将其作为 URI 源传递给图像组件,例如:
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
这可能晚了,但对我有用。我对存储提出了单独的请求,getDownloadURL() 在 rnfirebase v6 中的 putFile() 上不可用。
const ref = firebase.storage().ref("images/name.jpg");
ref.getDownloadURL()
.then(url => {console.log(url)})
.catch(e=>{console.log(e);})