2015-05-19 23 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