i have written a small uploader that look like this:
app.post('/upload/new', require开发者_如何学GosLogin, function(req, res) {
req.form.complete(function(err, fields, files) {
if(err) {
next(err);
} else {
ins = fs.createReadStream(files.upload.path);
ous = fs.createWriteStream(__dirname + '/public/uploads/' + files.upload.filename);
util.pump(ins, ous, function(err) {
if(err) {
next(err);
} else {
res.redirect('/upload');
}
});
}
});
});
everything is fine. but i would like to give a feedback to the user how far it is.
have you an idea how could it work?
THX!!!
there's also a progress listener:
req.form.on('progress', function (bytesReceived, bytesExpected) {
var percent = (bytesReceived / bytesExpected * 100) | 0;
console.log("uploading: " + percent);
});
精彩评论