2015-05-19 24 views
0

我正在上传我的服务器模块,并设置了文件上传与多方。目前我正在试图限制上传大小只是IA做这样节点js上传大小单元奇怪

req.on("data", function(dt) { 
       bytes += dt.length; 
       if (bytes > 2048) { 
       req.connection.destroy(); 
       console.log("connection destroyed due to huge file size"); 
       } 
       console.log(bytes); 

      }); 

东西,我觉得这个长度以字节为单位,并试图与2MB 限制,但我注意到了这个单元是测试我上传了一个有点怪一个148 kb的文件,但迄今为止创建的变量的长度是421,它既不是位也不是字节,为什么它是如此奇怪的数字?这额外〜300K从哪里来? on top 421 is length of variable bytes and at bottom the size comes frommultiparty whic is accurate

回答

0

您是否试图使用filesystem module来检查文件大小?

E.g.

var fs = require("fs"); 
var stats = fs.statSync("myfile.txt"); 
var fileSizeInBytes = stats.size; 
+0

在数据尚未到来的时候在空中学习这一点 – nikoss