node.js - 使用 muller 存储的 MEAN 堆栈显示图像
问题描述
我正在为我的 Web 应用程序使用 MEAN 堆栈。我成功地能够在节点服务器上存储多个图像文件,并将其路径与其他信息一起保存在 MongoDB 中。当我发出获取数据的请求时。如何将图像文件数组和其他信息发送回客户端?
数据库中存储的内容是
[
{
"paintingFileLocations": [
{
"fieldname": "artFileLocations",
"originalname": "logo1.png",
"encoding": "7bit",
"mimetype": "image/png",
"destination": "artImages/paintings",
"filename": "painting&1619496101680&logo1.png",
"path": "artImages/paintings/painting&1619496101680&logo1.png",
"size": 95523
},
{
"fieldname": "artFileLocations",
"originalname": "logo2.png",
"encoding": "7bit",
"mimetype": "image/png",
"destination": "artImages/paintings",
"filename": "painting&1619496101684&logo2.png",
"path": "artImages/paintings/painting&1619496101684&logo2.png",
"size": 94132
}
],
"paintingName": "Painting 1",
}
]
这是我的获取请求
router.get('/', function(req, res) {
Paintings.find({})
.then(paintings => { res.send(paintings) })
.catch(error => console.log(error))
});
解决方案
所以你正在为此使用NodeJS......你将拥有的东西是
app.post('/route', (req, res, next) => {
...
//code to upload the image
...
// fetch this object from MongoDB
const object = Model.find('---');
// here return the object in the response
res.status(200).send(object)
})
推荐阅读
- json - Angular 6:无法从不同组件的 JSON 对象中获取单个数据
- python - 在字典中搜索键并返回键和值
- python - JSONDecodeError: Expecting value.. 在执行 HTTP GET 请求时
- python - 找不到页面 (404) - 当前路径 editEstHab/ 与其中任何一个都不匹配
- javascript - 如何在 Angular Fire 项目中使用云功能?
- android - 如何使用 api 29 为 android 中的元素添加阴影
- video-streaming - Google Drive、Dropbox 等如何在您的浏览器中流式传输任何上传的视频文件格式
- android - 仅在目录中列出文件时,如何仅检索不包括路径的文件名?
- javascript - 我有一个带有这个参数的 onChange 函数可以正常工作,但我也想应用函数 onLoad
- java - 将数组从 strings.xml 添加到另一个 ArrayList