我在MongoDB中存储小图像
我成功retrieved an Image没有问题
当我试图将图像包含在一个对象中时,我最终失败了一个图像表示为一个我无法转换为base64数据的数组。
我的问题:
是否可以发送包含在具有多个字段的对象内的图像数据?
如果我参考链接,而不是:
res.send(doc.img.data);
我想这样做:
res.send(doc);
修改
添加我的工作代码:
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);
})
我想发送整个公司的对象:
return res.send(company);
但是我得到了在客户端表示为数组的company.file.data ...