开发者

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

开发者 https://www.devze.com 2023-03-24 16:54 出处:网络
i have written a small uploader that look like this: app.post(\'/upload/new\', require开发者_如何学GosLogin, function(req, res) {

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

精彩评论

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