【问题标题】:How to send application/octet-steam image data to Microsoft Face API in Node.js?如何在 Node.js 中将应用程序/八位字节流图像数据发送到 Microsoft Face API?
【发布时间】:2018-04-07 20:54:46
【问题描述】:

我想将 Octet-Stream 二进制数据发送到 Nodejs 中的 Microsoft Face API。我有一个 base64 编码的图像数据。我想将它发送到人脸 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."
   }
}

【问题讨论】:

标签: javascript microsoft-cognitive


【解决方案1】:

代替

request.post({
    data: buff
}

request.post({
    body: buff
}

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 2017-10-21
    • 1970-01-01
    • 2018-05-04
    • 2012-05-20
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    相关资源
    最近更新 更多