开发者

Giving feedback to user while uploading file with Node.js Express and connect-form

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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜