Sending image as binary via require(“http”) request to a remote server

后端 未结 1 1770
不知归路
不知归路 2021-01-24 07:49

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 choos

相关标签:
1条回答
  • 2021-01-24 08:27

    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.

    0 讨论(0)
提交回复
热议问题