Gautham Badhrinathan Gautham Badhrinathan - 1 year ago 124
CoffeeScript Question

Upload Progress — Request

I'm uploading a file using


req = url: "", body: fileAsBuffer, (err, res, body) ->
console.log "Uploaded!"

How do I know how much data has actually been uploaded? Is there some event that I can subscribe to or is there a property of the
that I can poll?

If none, what would be the best approach to upload data and know how much has been uploaded?

Answer Source

I needed a handle on the upload progress for yet another project of mine.

What I found out is that you can poll the request's connection._bytesDispatched property.

For example:

r = url: "", body: fileAsBuffer
setInterval (-> console.log "Uploaded: #{r.req.connection._bytesDispatched}"), 250

Note: If you were piping to r, poll r.req.connection.socket._bytesDispatched instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download