Image saved in s3 is downloaded as a stream and it is piped to duplex stream. The stream which is coming from s3 should be sent in formdata to another remote URL which when done with fs.createReadStream works but not with the duplex stream.
code
const download = (url, duplex) => {
axios
.request({
url,
method: "GET",
responseType: "stream",
})
.then((response) => {
response.data.pipe(duplex);
});
};
const mainFunction = () => {
const duplex = new PassThrough();
download("some_url", duplex);
// duplex.pipe(writeStream) works and writes to file
// send formdata
const form = new FormData();
form.append("file", duplex); // should work? as it is duplex
// this does not work
await axios.post(url, form, {
"Content-Type": "multipart/form-data",
...form.getHeaders(),
});
};
So here is what was missing and finally found it. Some destination expects file mimeType when you're sending stream in
formdata.Solution