got: GOT not able to handle Passthrough streams
Current Behaviour Hi, I am trying to upload the file stream to another server. Please check the code below
const fd = new FormData({
readable: true
});
const stream = getFileStream();
fd.append('file', stream, {
filename: 'upload.txt',
});
await got.post('http://localhost:3001/upload', {
body: fd,
});
Hi, I am creating a file stream like the below snippet.
const getFileStream = () => {
const fileStream = createReadStream(filePath);
const passThrough = new PassThrough();
return fileStream.pipe(passThrough);
};
I have to use passthrough for some reasons.
If I do something like the above I get an error ‘ERR_GOT_REQUEST_ERROR’
But if I change getFileStream function like below it works basically I am not using Passthrough
const getFileStream = () => {
const fileStream = createReadStream(filePath);
const passThrough = new PassThrough();
return fileStream;
};
If I do the same in Axios and node fetch it’s working with passthrough.
Expected Behaviour: It should upload the file
Node Version v14.18.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (3 by maintainers)
@octet-stream @szmarczak Removing the Content-Length header fixed the issue. Now I am able to use passthrough streams. Below I am pasting the working code so that it will act as a reference for someone facing the same issue
Thanks a lot for the help @octet-stream @szmarczak