0

I want to send Octet-Stream binary data to Microsoft Face API in Nodejs. I have a base64 encoded image data. I want to send it to the Face API. I'm using the following code:

var dataURItoBuffer = function (dataURL, callback) {
    var buff = new Buffer(dataURL.replace(/^data:image\/(png|gif|jpeg);base64,/, ''), 'base64');
    callback(buff);
};

var sendImageToMicrosoftDetectEndPoint = function (imageData, callback) {
    console.log('Entered helper');
    dataURItoBuffer(imageData, function (buff) {
        request.post({
            url: keyConfig.microsoftDetectURL,
            headers: {
                'Content-Type': 'application/octet-stream',
                'Ocp-Apim-Subscription-Key': keyConfig.microsoftApiKey
            },
            data: buff
        }, function (err, httpResponse, body) {
            console.log(body);
        });
    })
}

But it gives me this response:

{
  "error": {
     "code":"InvalidImageSize",
     "message":"Image size is too small."
   }
}
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
Aman Dwivedi
  • 174
  • 1
  • 10

1 Answers1

0

Instead of

request.post({
    data: buff
}

Do

request.post({
    body: buff
}
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130