我正在使用socket.io-stream上传文件,我想知道数据上传的大小限制。
这是我的服务器代码:
ss = require('socket.io-stream'),
SocketIo = require('socket.io'),
path = require('path'),
fs = require('fs');
let io = SocketIo.listen(server);
io.of("/users").on('connection',function(socket){
ss(socket).on('avatar-upload', function(stream, data) {
let filename = path.format({
root: '/',
dir: '/home/user/project/public/upload/',
base: data.name
});
});
// Check data stream size to limit here
})
我该怎么做?
答案 0 :(得分:0)
可能会有一些想法限制流大小
var blobStream = ss.createBlobReadStream(file);
var size = 0;
blobStream.on('data', function(chunk) {
size += chunk.length;
console.log(Math.floor(size / file.size * 100) + '%');
// -> e.g. '42%'
});
blobStream.pipe(stream);