javascript - Stream file uploaded with Express.js through formidable and gm to eliminate double write -
i want upload , resize image in 1 go without writing disk twice.
to upload image use: node-formidable: https://github.com/felixge/node-formidable
to resize image use: gm: http://aheckmann.github.com/gm/
when run code error: 'this socket closed'.
error: spawn enoent @ errnoexception (child_process.js:988:11) @ process.childprocess._handle.onexit (child_process.js:779:34)
my code:
function uploadphotos (req, res) { // parse file upload var form = new formidable.incomingform(); form.multiples = true; // allow multiple files html5 multiple attribute. form.maxfields = 100; // maximum number of fields (no files). form.keepextensions = true; // include extensions of original files. form.uploaddir = original_images_dir; form.onpart = function (part) { if (!part.filename) { // let formidable handle non-file parts. return this.handlepart(part); } gm(part) .resize(200, 200) .stream(function (err, stdout, stderr) { stdout.pipe(fs.createwritestream(path.join(resized_images_dir, 'resized_' + part.filename))); stdout.on('end', function () { res.send(200); }); }); }; form.parse(req); }
i can't figure out problem is. similar problem can found here: stream file uploaded express.js through gm eliminate double write
any suggestions?
thanks!
i thought npm install trick didn't install graphicsmagick. installing graphicsmagick manually solved problem.
thanks tuck: gm stream stdout pipe throwing unhandled error
Comments
Post a Comment