Open gramakri opened 2 years ago
The reason the code hangs is because the 'drain' event is only emitted once at https://github.com/visionmedia/superagent/blob/048cf185d954028b1dccde0717d2488b2284c297/src/node/index.js#L799
Changing that bit of code to the below makes the upload work.
req.on('drain', () => {
this.emit('drain');
});
'drain' event can be emitted multiple times (each time req.write() returns false).
Uploading files larger than the read stream's highWatermark does not work.
This is tested with node 16.13.1
Sample server:
You can test the server itself works using
curl -F file=@largefile.txt -X POST http://localhost:3000/upload
Superagent upload code:
The code above will just "hang" if largefile.txt is more than twice the highWaterMark. For fs, the default water mark is 64KB. So, if the file is say 200KB, the upload code will hang.