【发布时间】:2015-07-16 11:02:43
【问题描述】:
我正在使用 GridFS 在 MongoDB 中存储来自 Angular 应用程序的图像。从数据库获取图像时出现问题。我只能在 iexplorer 和 postman 中显示图像。在 chrome、firefox 中,它看起来像损坏的图像。
有没有办法直接从数据库中以角度显示图像?我正在使用快递。并尝试插入这样的图像:<img src="upload/55a75dbb749062041b4c84ba"/>
我的路由器
router.get('/upload/:objectId',function(req, res){
var options = {
_id : req.params.objectId
};
gfs.exist(options, function(err, exists) {
if(!exists) {
res.status(404);
res.end();
} else {
res.set('Content-Type', 'image/jpeg');
var readstream = gfs.createReadStream(options);
readstream.pipe(res);
}
});
});
【问题讨论】: