Stream POST no response body #1626
Answered
by
szmarczak
ramtinsoltani
asked this question in
Q&A
-
What would you like to discuss?I'm using the stream API to upload a file: const stream = fs.createReadStream(path.resolve(process.cwd(), 'test.txt'));
const req = got.stream('http://localhost:5000/file/test.txt', {
headers: {
'Content-Type': 'application/octet-stream'
},
method: 'post',
throwHttpErrors: false,
retry: 0,
responseType: 'json'
})
.on('response', res => {
console.log(res.body);
})
.on('error', error => {
stream.close();
console.error(error);
});
stream.pipe(req); The How would I read the response body? Checklist
|
Beta Was this translation helpful? Give feedback.
Answered by
szmarczak
Feb 18, 2021
Replies: 1 comment 4 replies
-
It is a stream, not a promise, so you shouldn't go for |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
szmarczak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is a stream, not a promise, so you shouldn't go for
response.body
. Useget-stream
.