【问题标题】:how to split input file(image) stream in node js / sails js?如何在节点 js/sails js 中拆分输入文件(图像)流?
【发布时间】:2016-08-19 22:37:47
【问题描述】:

我想将输入流分成 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);
});

我应该做些什么改变? 我怎样才能做到这一点?

【问题讨论】:

    标签: node.js stream sails.js inputstream node-streams


    【解决方案1】:

    你可以使用skipper包来处理多上传

    在终端运行这个命令

    npm install skipper --save
    

    在控制器的顶部 app.use(require('skipper')());

    现在可以使用这个包了

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

    【讨论】:

    • 我已经在使用 skipper 上传文件.. 但我想先检查两个图像的大小然后上传文件.. 请查看this 的投票最多的答案。我正在使用相同的方法。但我找不到多个文件的解决方案
    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    相关资源
    最近更新 更多