I store small images in MongoDB.
I successfully retrieved an Image with no problems.
When i tried to include the image inside an object I failed ending up with an image represented as an array that i can not convert to base64 data.
My Question:
Is it possible to send an image data which is included inside an object with several fields?
If I refer to the link, instead of:
res.send(doc.img.data);
I would like to do:
res.send(doc);
EDIT:
Adding my working code:
company.file.data = new Buffer(fs.readFileSync(req.files.file.path), 'base64').toString('base64');
company.file.contentType = req.files.file.type;
// Data is not delivered as string but as an array
company.save(function(err, company) {
if (err)
throw err;
res.contentType(company.file.contentType);
return res.send(company.file.data);
})
I woule like to send the whole company object:
return res.send(company);
But then i get the company.file.data represented as an array on the client side...