gpt4 book ai didi

javascript - 通过formidable和gm使用Express.js上传的流文件,消除双写

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:48 24 4
gpt4 key购买 nike

我想一次性上传图像并调整图像大小,而不需要两次写入磁盘。

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

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

当我运行此代码时,出现错误:“此套接字已关闭”。

Error: spawn ENOENT at errnoException (child_process.js:988:11) at 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

有什么建议吗?

谢谢!

最佳答案

我认为 npm install 可以解决问题,但它没有安装 GraphicsMagick。手动安装 GraphicsMagick 解决了我的问题。

感谢塔克: gm stream stdout pipe throwing unhandled error

关于javascript - 通过formidable和gm使用Express.js上传的流文件,消除双写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23187545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com