Skip to content

GOT not able to handle Passthrough streams #2111

@vijhhh2

Description

@vijhhh2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions