ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

Node Download Progress Never Fires #1604

Open allout58 opened 3 years ago

allout58 commented 3 years ago

I'm trying to use the .on('progress', cb) method for a download in my Node application, but the callback function is never called. For uploads, .on('progress', cb) works just fine.

Relevant versions:

Download example (does not work):

agent()
  .get(downloadUrl)
  .maxResponseSize(this.maxDownloadSize ?? 200_000_000)
  .on('progress', ev => {
    console.log('Progress: ', ev.loaded);
   })
  .then(r => {
    console.log("Response body: ', r.body);
  });

Upload example (works):

agent()
  .post(uploadUrl)
  .attach('file1', bufferToUpload, {filename: 'thing1.zip', contentType: 'application/zip'})
  .on('progress', ev => {
    console.log('Progress: ', ev.loaded);
  })
  .then(r => {
    console.log("Response body: ', r.body);
  });
bear-boss commented 3 years ago

I met the same problem.