【问题标题】:Stream file uploaded with Express.js through formidable and gm to eliminate double write使用Express.js上传的流文件通过强大和gm消除双重写入
【发布时间】:2014-06-04 22:28:07
【问题描述】:

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

上传我使用的图片:node-formidablehttps://github.com/felixge/node-formidable

要调整我使用的图像大小:gmhttp://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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 2021-03-07
      • 2018-09-25
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      相关资源
      最近更新 更多