[英]How do you upload a new file with a JSON on Firebase Storage using Firebase Functions?
[英]How do you render an image from Firebase Storage using .map method?
我正在尝试使用 Firebase 存储中的 .Map() 方法结合 Firestore 为每个组件渲染图像。
{Object.values(getData).map((data, index) => {
getDownloadURL(ref(storage, `events/${data.name + data.artist + data.date + data.description}` ))
.then((url) => {
setImageSet(url)
console.log(imageSet)
})
return(
<CssVarsProvider>
<Card variant="outlined" sx={{ width: 300, marginRight: 5}}>
<AspectRatio>
<div>
<img src={imageSet}/>
</div>
</AspectRatio>
<Typography mt={2}>{data.name}</Typography>
<Typography level="body2">{data.description}</Typography>
</Card>
</CssVarsProvider>
)
})}
当我在 Firestore 上创建 1 个测试数组时,图像呈现。 但是如果我创建两个,那么它就像是试图在 1 个组件上渲染两个图像。 我该如何解决? 对不起,如果我不够清楚,因为这是我第一次在 Stackoverflow 上发帖。
干杯
我已通过将 URL 值直接分配给 firestore 来解决此问题。
const uploadImage = async () => {
if (imageUpload == null) return
const imageRef = ref(storage, `events/${eventName + artistName + eventDate + eventDescription}`)
uploadBytes(imageRef, imageUpload).then(() => {
console.log("image uploaded")
getDownloadURL(imageRef)
.then((url) => {
setGetImage((prev) => [...prev, url])
console.log(getImage)
})
})
}
const uploadData = async () => {
await setDoc(doc(db, "events", eventName), {
name: eventName,
artist: artistName,
date: eventDate,
description: eventDescription,
uri: getImage,
})
console.log("db added")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.