使用Express.js通过强大和gm上传的stream文件消除双重写入

我想一次性上传和调整图像的大小,而不用两次写入磁盘。

要上传我使用的图像: node-formidable : https : //github.com/felixge/node-formidable

调整我使用的图像大小: gm : http : //aheckmann.github.com/gm/

当我运行这个代码,我得到一个错误:'这个套接字被closures'。

错误:在Process.ChildProcess._handle.onexit(child_process.js:779:34)errnoException(child_process.js:988:11)处产生ENOENT

我的代码:

function uploadPhotos (req, res) { // parse a file upload var form = new formidable.IncomingForm(); form.multiples = true; // Allow multiple files with HTML5 multiple attribute. form.maxFields = 100; // Maximum number of fields (no files). form.keepExtensions = true; // Include the extensions of the original files. form.uploadDir = ORIGINAL_IMAGES_DIR; form.onPart = function (part) { if (!part.filename) { // Let formidable handle all 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); } 

我找不出什么问题。 类似的问题可以在这里find: streamfile upload与Express.js通过GM来消除双重写

有什么build议么?

谢谢!

我以为npm安装会做的伎俩,但它并没有安装GraphicsMagick。 手动安装GraphicsMagick解决了我的问题。

感谢tuck: gm stream stdoutpipe道抛出未处理的错误