在节点中的一个文件中读取的时候,我遇到了类似的问题字节数组缓冲区并将其发送给Rekognition。
我解决它,而不是通过阅读在Base64表示,然后把它变成一个缓冲区这样的:
const aws = require('aws-sdk');
const fs = require('fs');
var rekognition = new aws.Rekognition({
apiVersion: '2016-06-27'
});
// pull base64 representation of image from file system (or somewhere else)
fs.readFile('./test.jpg', 'base64', (err, data) => {
// create a new buffer out of the string passed to us by fs.readFile()
const buffer = new Buffer(data, 'base64');
// now that we have things in the right type, send it to rekognition
rekognition.detectLabels({
Image: {
Bytes: buffer
}
}).promise()
.then((res) => {
// print out the labels that rekognition sent back
console.log(res);
});
});
这也可能是相关的人获得:Expected params.Image.Bytes to be a string, Buffer, Stream, Blob, or typed array object
消息。
我也在寻找如何做到这一点的答案,因为我一直无法做到这一点。我曾尝试使用Base64编码的字符串,其结果与上面相同,并尝试将其转换为Uint8array,Blob和ArrayBuffer,但仍未取得成功。有没有人有一个可行的例子?我的源数据位于HTML5 Canvas对象中。 –