I'm using fetch to download a file and there is a problem I'm facing when using fetch that does not happen when I download the file manually on the browser. Maybe I'm missing something here?
the code looks like this:
fetch(link).then(res => {
let writeStream = fs.createWriteStream(destinationPath)
writeStream.on('close', callback);
res.body.pipe(writeStream)
})
Many times the stream just hangs and so I added a settimeout to reattempt download. sometimes it takes many attempts to get it to finish. This does not happen when using the browser (if it does very rarely). Is there some setting that I should adjust for fetch to work properly here? or is my code not correct?
A sample download file is: link
UPDATE: Forgot to mention that I'm using node-fetch on the server.
Thanks!