Javascript 如何通过nodejs提供从mongoDB到Image(JPG)的下载链接
我已将图像存储在MongoDB(缓冲区)中 现在我想在我的react原生应用程序中使用此图像 通过像这样的url e、 ghttp://localhost:8080/fullImg.jpeg 我该怎么做 这是我的MongoDB模式Javascript 如何通过nodejs提供从mongoDB到Image(JPG)的下载链接,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,我已将图像存储在MongoDB(缓冲区)中 现在我想在我的react原生应用程序中使用此图像 通过像这样的url e、 ghttp://localhost:8080/fullImg.jpeg 我该怎么做 这是我的MongoDB模式 const listingSchema = mongoose.Schema({ title: String, image:{ fullImg: { imgBuffer: Buffer, contentType: String }, },
const listingSchema = mongoose.Schema({
title: String,
image:{
fullImg: { imgBuffer: Buffer, contentType: String },
},
price: Number,
})
const Listing = new mongoose.model("Listing", listingSchema);
当前我正在将此缓冲区发送到应用程序和
将其转换为base64
如果可以告诉您存储和检索mongo db图像的最佳方法,那么最佳做法是将图像上载到某些存储(Amazon S3、Google Cloud storage…),然后将上载图像的
url
存储到MongoDB
。从MongoDB
获取数据后,只需将img
标记的src
属性设置为上传图像的url
如果您想使用在MongoDB中存储缓冲区的方法,可以在HTML
中显示base64
数据,如下所示:
<img src="data:image/png;base64, {{your_base64_data}}"/>
谢谢,但我怎样才能提供这样的URL???