如何在节点 JS / Sails JS 中拆分输入文件(图像)流



我想将输入流拆分为 2 个流。因为我通过文件上传发送 2 张图像..

所以在我的控制器中我是这样写的

req.file('image')._files[0].stream

这包含 2 图像的详细信息。例如,长度显示 2 个图像的总和。

所以我想要的是像下面这样舒缓:

//calculate length of 1st image
var dataLength =0;        
req.file('image')._files[0].stream.on('data', function (chunk) {
    dataLength += chunk;
})
.on('end', function () {  // done
    console.log('The length of 1st was:', dataLength);
});
//calculate length of 2nd image
var dataLength2 =0;        
req.file('image')._files[0].stream.on('data', function (chunk) {
    dataLength2 += chunk;
})
.on('end', function () {  // done
    console.log('The length of 2nd was:', dataLength2);
});

我应该进行哪些更改?我怎样才能做到这一点?

您可以使用skipper package来处理多上传

在终端中运行此命令

npm install skipper --save

位于控制器顶部 app.use(require('skipper')());

现在可以使用此包

req.file('image').upload({
  // ...any other options here...
}, ...);

最新更新