【发布时间】:2015-03-23 18:17:00
【问题描述】:
我是 gridfs mongodb 的新手,我创建了一个 POST 服务来接收字节(视频)并希望将字节保存在 mongodb 中。我研究过gridfs,但无法获得清晰的画面。我已经编写了代码,但我不知道它是否足以处理大文件。或者如何从设备接收字节并以任何最佳方式存储在 gridfs 中?或任何其他方式来存储视频(字节)?很感谢任何形式的帮助。下面是代码。
var bytes = [];
bytes = req.param('video');
var db = new Db('myDB', new Server('localhost', 27017,{w:1}));
db.open(function(err, db) {
// Our file ID
var fileId = new ObjectID();
// Open a new file
var gridStore = new GridStore(db, fileId, 'w');
gridStore.open(function(err, gridStore) {
//Write a buffer
gridStore.write(new Buffer(bytes), function(err, gridStore) {
// Close the
gridStore.close(function(err, result) {
// Read back all the written content and verify the correctness
GridStore.read(db, fileId, function(err, fileData) {
console.log(fileData);
db.close();
});
});
});
// });
});
});
【问题讨论】:
标签: node.js mongodb gridfs gridfs-stream