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

Restart an aborted upload #1557

Open jamiek-acl opened 4 years ago

jamiek-acl commented 4 years ago

I am using superagent v5.1.0 in a React file uploader component I am building. As a file is being uploaded, the component allows me to click a button and cancel the upload. Then I can click another button to restart it.

First I start my upload:

const formData = new FormData();
formData.append("file", theImageFile);

superagent
  .send(formData)
  .on('progress', () => { ... })
  .end((err, response) => { ... })

Then I cancel my upload:

superagent.abort();

Finally, I restart my upload (same code as when start it) and superagent throws the error: "Can't merge these send calls". The error can be seen here: https://github.com/visionmedia/superagent/blob/56ce51728083392132505218c05edd5cf9f60c58/src/request-base.js#L609

How can I get around this? Is this possible in superagent?

Thanks.