【发布时间】: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."
}
}
【问题讨论】:
-
如果你还在苦苦挣扎,请看stackoverflow.com/a/58854505/2627126。
标签: javascript microsoft-cognitive