I have a String and I want to convert it to a stream to send it as if it were a file via multipart
of request
.
I want to do it in the air, without generating the file on disk.
I'm doing it this way:
const stream = require("stream")
module.exports = function () {
let readStream = new stream.PassThrough()
readStream.end(new Buffer('<file data>'), () => {
const options = {
url: '<url>',
method: 'POST',
json: true,
formData: {
file: readStream
}
};
request(options, (error, res)=> {
if(error) {
console.log(JSON.stringify(error))
}
});
})
})
}
... and it returns the following error:
{
"code":"BadRequestError",
"message":"MultipartParser.end(): stream ended unexpectedly: state = PART_DATA"
}