1

On server side, I have this:

  app.post('/testReadStream', function(req, res) {
    var readStream = req.body;
    readStream.pipe(process.stdout);
  })

}).listen(443, () => console.log(`Listening on 443`));

I am making the following request from somewhere else:

let readStream = fs.createReadStream(path);
const fileSizeInBytes = fs.statSync(path).size;

fetch('https://localhost:443/testReadStream', {
    method: 'POST',
    headers: {
        "Content-length": fileSizeInBytes
    },
    body: readStream

}).catch((err) => {
    console.log(err);
})

I get the following error.

   'request to https://localhost:443/testReadStream failed, reason: write EPROTO 4365467072:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n',

From this link https://github.com/openssl/openssl/issues/10938 it seems I did something wrong with filestreams. I copied it from here How to send a file in request node-fetch or Node?

What did i do wrong?

Qrow Saki
  • 932
  • 8
  • 19

2 Answers2

1

Looks like an SSL problem. Can you try a simple string body

 body: "text"
arlac77
  • 81
  • 3
0

The SSL problem came from me putting "https" + localhost instead of "http://localhost". .-.

After that, all I had to change was req.body to req.

Qrow Saki
  • 932
  • 8
  • 19