Firebase 从Firestore检索/处理图像URL-React Native
我是React Native和Firebase(Firestore)的新手,我正在开发一个应用程序,在这个应用程序中,我必须检索到我的订阅源中的帖子 我可以检索所有需要的数据,但我不知道如何在前端显示图像。post文档有一个字段图像,该图像保存为URL并存储在Firebase存储器中 有人知道如何显示图像吗?我正在使用一个函数对数据进行排序 这是my retrieveData(),它会打印正确的URL:Firebase 从Firestore检索/处理图像URL-React Native,firebase,react-native,google-cloud-firestore,react-native-flatlist,Firebase,React Native,Google Cloud Firestore,React Native Flatlist,我是React Native和Firebase(Firestore)的新手,我正在开发一个应用程序,在这个应用程序中,我必须检索到我的订阅源中的帖子 我可以检索所有需要的数据,但我不知道如何在前端显示图像。post文档有一个字段图像,该图像保存为URL并存储在Firebase存储器中 有人知道如何显示图像吗?我正在使用一个函数对数据进行排序 这是my retrieveData(),它会打印正确的URL: retrieveData() { var that = this; le
retrieveData() {
var that = this;
let postRef = firebase
.firestore()
.collection("posts")
.orderBy("timestamp", "desc")
.limit(10);
let allPosts = postRef
.get()
.then((snapshot) => {
snapshot.forEach((doc) => {
var post = that.state.posts;
const data = (doc.id, "=>", doc.data());
that.setState({ posts: post });
console.log(data.image);
post.push({
id: data.id,
title: data.title,
description: data.description,
expireDate: data.expireDate,
timestamp: data.timestamp,
image: data.image,
});
});
})
.catch((err) => {
console.log("Error getting documents", err);
});
}
这就是我在平面列表中调用图像的方式:
<Image
source={post.image}
style={styles.postImage}
/>
有人能帮我吗
提前谢谢。你能分享图片的url吗?首选方法是将图像存储在firebase存储上,获取下载url,然后将该url存储在firestore文档中
fileref.put(file)
.then(snapshot => {
return snapshot.ref.getDownloadURL(); // Will return a promise with the download
link
})
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link - ${downloadURL}`);
return downloadURL;
})
.catch(error => {
// Use to signal error if something goes wrong.
console.log(`Failed to upload file and get link - ${error}`);
});
嗨,伊姆贾德,谢谢你的回复。是的,我正在firebase存储上存储图像,并获取Firestore文档的URL。但当我从文档中检索数据时,它会正确返回控制台上的链接,但不会在前端下载图像!这就是我遇到问题的地方@JackieMedeiros你找到解决这个前端问题的方法了吗?