Reputation: 263
I am using a MEAN stack for my web application. I am successfully able to store multiple image files on node server and save its path in MongoDB with other information. When I make get request to retrieve the data. How can I send both the image file array and other information back to client?
What is stored in Database is
[
{
"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",
}
]
This is my get request
router.get('/', function(req, res) {
Paintings.find({})
.then(paintings => { res.send(paintings) })
.catch(error => console.log(error))
});
Upvotes: 0
Views: 47
Reputation: 11
So you are using NodeJS for this... What you will have something is
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)
})
Upvotes: 1