用的代码很简单:
app.use(express.bodyParser({
uploadDir:__dirname + '/uploadfile/group/icon',
keepExtensions:true,
defer:true, //enable event
limit:10000000
}));
app.disable("multipart");
app.post('/upload',function(req, res){//bind event handler
req.form.on('progress',function(bytesReceived, bytesExpected){
console.log(((bytesReceived / bytesExpected)*100)+"% uploaded");});
req.form.on('end',function(){
console.log(req.files);
res.send("done");});
});
但是上传后发现有的图片完整上传,有的不完整,对比如下:
而且奇怪的是bytesReceived竟然比bytesExpected还要大。。
4 回复