如何将应用程序/八位字节 - 蒸汽图像数据发送到Node.js中的Microsoft Face API?

时间:2018-04-07 20:54:47

标签: javascript microsoft-cognitive

我想将Octet-Stream二进制数据发送到Nodejs中的Microsoft Face API。我有base64编码的图像数据。我想将它发送到Face API。我正在使用以下代码:

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);
        });
    })
}

但它给了我这样的回应:

{
  "error": {
     "code":"InvalidImageSize",
     "message":"Image size is too small."
   }
}

1 个答案:

答案 0 :(得分:0)

而不是

uSoup = BeautifulSoup(b.text, 'html.parser')
data = uSoup.find_all('script')[16].string

request.post({
    data: buff
}