【发布时间】:2014-06-04 22:28:07
【问题描述】:
我想一次性上传并调整图像大小,而不需要写入磁盘两次。
上传我使用的图片:node-formidable:https://github.com/felixge/node-formidable
要调整我使用的图像大小:gm:http://aheckmann.github.com/gm/
当我运行此代码时,我收到一个错误:“此套接字已关闭”。
错误:生成 ENOENT 在 errnoException (child_process.js:988:11) 在 Process.ChildProcess._handle.onexit (child_process.js:779:34)
我的代码:
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);
}
我不知道问题出在哪里。 类似的问题可以在这里找到:Stream file uploaded with Express.js through gm to eliminate double write
有什么建议吗?
谢谢!
【问题讨论】:
标签: javascript node.js express graphicsmagick