Reputation: 629
I want to download a file from an url with got library, this is my current code:
var data
try
{
var stream = got.stream (url)
stream.on ('data', d => data += d)
stream.end ()
}
catch (error)
{
console.error (error)
}
But i'm getting this error:
TypeError: The payload has been already provided
Upvotes: 2
Views: 1215
Reputation: 4332
got.stream()
makes a GET request by default, you need to set allGetBody
to true
to avoid the TypeError
.
So do this instead:
var data
try {
var stream = got.stream (url, { allowGetBody: true })
stream.on ('data', d => data += d);
stream.end()
} catch (error) {
console.error (error)
}
See Got Documentation on this
Here's a working example on Javascript Runkit
Upvotes: 2