【发布时间】:2016-01-07 05:29:46
【问题描述】:
我需要从 GridFS 下载简历,下面是我编写的代码,但这似乎没有给我一个物理文件供我下载,这是用来读取内容的。如何下载文件?
exports.getFileById = function(req, res){
var conn = mongoose.connection;
var gfs = Grid(conn.db, mongoose.mongo);
var id = req.params.ID;
gfs.exist({_id: id,root: 'resume'}, function (err, found) {
if (err) return handleError(err);
if (!found)
return res.send('Error on the database looking for the file.');
gfs.createReadStream({_id: id,root: 'resume'}).pipe(res);
});
};
【问题讨论】: