I am trying to take an image url get the image then write it to the filesystem then resize it. At the end of the resizing I would like to return it back to the response so the client gets the image. Right now the stdout.pipe(res) is not returning and I get an events.js:72 error: throw er; // Unhandled 'error' event.
Am I missing anything obvious?
exports.getImage = function(req, res, next) {
var fileId = Math.uuid();
var i = request.get(req.params.image).pipe(fs.createWriteStream(fileId));
i.on('close', function () {
gm(fileId)
.resize('200', '200')
.stream(function (err, stdout, stderr) {
if (err) next(err);
stdout.pipe(res);
})
});
};