当我InvalidImageFormatException
试图将图像传递给AWS Rekognition
. 我向Image URL发出 HTTP 请求,下载图像并将缓冲区传递给 aws 函数。
这是它的代码:
const AWS = require('aws-sdk');
const axios = require('axios');
let rekognition = new AWS.Rekognition({apiVersion: '2016-06-27', region: 'us-east-1'});
let url = 'http://www.xsjjys.com/data/out/43/WHDQ-511895361.jpg'
axios({
method: 'GET',
url,
responseType: 'arraybuffer'
})
.then(response => {
console.log(response)
let params = {
Image: {
Bytes: response.data
},
Attributes: ['ALL']
};
rekognition.detectFaces(params, (err, data) => {
if(err) console.log(err);
else console.log(JSON.stringify(data));
});
})
.catch(err => console.log(err));
我不明白这个错误可能是什么原因。它适用于其他图像,但对某些图像会引发错误。这可能是什么原因?
这是跟踪:
{ InvalidImageFormatException: Invalid image encoding
at Request.extractError (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/protocol/json.js:48:27)
at Request.callListeners (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /home/suhail/nodejs/test/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/home/suhail/nodejs/test/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
message: 'Invalid image encoding',
code: 'InvalidImageFormatException',
time: 2018-04-03T13:28:43.404Z,
requestId: 'edd8fccf-3742-11e8-95a3-c58fca411044',
statusCode: 400,
retryable: false,
retryDelay: 55.96279161227613 }