I'm trying to save a file into GridFS in node.js. The usecase is actually really straight forward: "upload a file to a restify app, save it into 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();
});
}
The console tells me
could not save: [RangeError: Maximum call stack size exceeded]
and since this is fired from an event, I don't have a stacktrace. Anyway nothing is written into GridFS.
Since on my part there is no recursion, I thought it has to be on gridfs-stream or mongodb's side, and since those are tested, I tried to simply higher the --stack-size
, this resulted in a Segmentation Fault.
This is my environtment: https://github.com/semmypurewal/node-dev-bootstrap