Node-formed and simple progress bar

If I look into the documentation containing node, I can read:

"Event: 'progress' (bytesReceived, bytesExpected)
Emitted after each incoming chunk of data that has been parsed. 
Can be used to roll your    own progress bar."

I am wondering how to implement my own progress bar. I mean, how to read this side of client information? I am completely confused. Is it implemented using a GET poll that starts after POST starts, or can I read the information from the POST request at boot time?

If I look at this:

http.createServer(function(req, res) {
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    var form = new formidable.IncomingForm();
    form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(sys.inspect({fields: fields, files: files}));
    });
    return;
  }

See how / upload url handles the POST request and returns something res.write ('received download: \ n \ n');

My question is: who can read that

res.write('received upload:\n\n');
+5
source share
3 answers

You do not need to redefine the hook onPart!

, progress :

form.on('progress', function(bytesReceived, bytesExpected) {
  var progress = {
    type: 'progress',
    bytesReceived: bytesReceived,
    bytesExpected: bytesExpected
  };

  socket.broadcast(JSON.stringify(progress));
});

.

+6

socket.io

hook onPart.

incomingForm.onPart = function(part) {
  part.addListener('data', function() {
    // send back to the client the status
  });
}
+3

, - AJAX, xhr.upload.onprogress :

xhr.upload.onprogress = (e) => {
  if (e.lengthComputable) {
    console.log(`${e.loaded} out of ${e.total} bytes have been uploaded`)
  }
}

. . . .

0

All Articles