如何获取使用gridform保存的文件?

时间:2013-09-17 16:34:47

标签: node.js mongodb express gridfs

我正在使用gridform在gridfs中保存文件,如何让文件将其返回给用户?

1 个答案:

答案 0 :(得分:0)

可能的解决方案,看documentation here

gridfsstream = require('gridform/node_modules/gridfs-stream')
mongoose = require('mongoose')

var conn = mongoose.createConnection(..);
conn.once('open', function () {
  // oid: string representing object id, identifier of a gridfs file
  // res: express response object
  gridfsstream(conn.db, mongoose.mongo).createReadStream(oid).pipe(res);
})