当我尝试将图像传递给AWS重新认知时,获得无效的幻影感受



我试图将图像传递给 AWS Rekognition时得到 InvalidImageFormatException。我向图像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 }

您的映像链接" http://www.xsjjys.com/data/43/whdq-511895361.jpg"重定向到html页:

curl -v "http://www.xsjjys.com/data/out/43/WHDQ-511895361.jpg"    (510ms)
*   Trying 144.76.74.241...
* TCP_NODELAY set
* Connected to www.xsjjys.com (144.76.74.241) port 80 (#0)
> GET /data/out/43/WHDQ-511895361.jpg HTTP/1.1
> Host: www.xsjjys.com
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Tue, 03 Apr 2018 13:59:42 GMT
< Content-Type: text/html
< Content-Length: 178
< Location: http://www.xsjjys.com/511895361.html
< Connection: keep-alive
< Expires: Tue, 03 Apr 2018 13:59:42 GMT
< Cache-Control: max-age=0
< Cache-Control: no-store, no-cache, must-revalidate
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host www.xsjjys.com left intact

这意味着您正在传递HTML数据,而不是图像数据,这就是Rekognition不适用于它的原因。看起来像该站点上的某种反链接设置。您可能需要通过一些cookie或正确的HTTP推荐人标头。但是目前,我只需尝试在其他地方托管的图片。

最新更新