Skip to content Skip to sidebar Skip to footer

Sending Image As Binary Via Require("http") Request To A Remote Server

I'm trying to send an image to remote server from nodejs server. Here's the request format so far. Note: Just like binary request in postman and choosing a file and sending) functi

Solution 1:

I think you just want this:

fs.createReadStream('./img/thumbnail.png').pipe(https.request({
  hostname: 'hostname',
  path: '/upload',
  method: 'PUT',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'image/png',
  }
}, function (response) { ... }));

The issue with your code is that you were putting the body into options.body, but per the documentation, it doesn't look like there is any such option.

Post a Comment for "Sending Image As Binary Via Require("http") Request To A Remote Server"