我正在尝试将文件保存到 node.js 中的 GridFS 中。用例实际上非常简单:“将文件上传到 restify 应用程序,将其保存到 GridFS 中”。
function put(req, res, next) {
var ws, filename;
var application = new Application(req.params);
if (req.files.cv) {
filename = application._id + '/' + req.files.cv.name;
ws = gfs.createWriteStream({
filename: filename,
content_type: req.files.cv.type
});
ws.on('error', function (error) {
console.log('could not save: ', error);
});
fs.createReadStream(req.files.cv.path).pipe(ws);
application.files.push(filename);
}
/* cut */
application.save(function (err, application) {
/* cut */
next();
});
}
控制台告诉我
could not save: [RangeError: Maximum call stack size exceeded]
并且由于这是从事件触发的,因此我没有堆栈跟踪。无论如何,没有任何东西写入 GridFS。
由于我没有递归,我认为它必须在gridfs-stream或 mongodb 方面,并且由于这些都经过测试,我试图简单地提高--stack-size
,这导致了分段错误。