AWS Rekognition无法识别字节图片:InvalidParameterException报错求助
问题排查与解决
核心错误原因
AWS Rekognition的DetectFaces接口要求Image参数必须包含Bytes(字节数据)或S3Object(S3对象信息)字段,你的代码里错误地将Uint8Array赋值给了自定义的image键,导致接口无法识别有效图片数据。
具体修改步骤
1. 修正verifyImage函数的参数结构
将Image对象中的image键改为Bytes,这是AWS SDK规定的字段名:
export async function verifyImage(image ) { console.log(image) const params = { Image:{ Bytes: image // 替换为正确的字段名Bytes }, Attributes: ['ALL'] }; const command = new DetectFacesCommand(params); // 补充发送命令并返回结果的代码 const response = await rekognition.send(command); return response; }
2. 优化async函数调用风格
moderateEachPic中无需在await后混用.then(),保持代码简洁:
const moderateEachPic = async (image) => { const imageBuffer = new Uint8Array(await image.arrayBuffer()) console.log(imageBuffer) // 直接用await接收结果 const res = await verifyImage(imageBuffer); // 后续处理逻辑... }
额外验证
从你提供的imageBuffer输出看,它是有效的Uint8Array字节数据,修改字段名后即可被AWS Rekognition正确识别。
内容的提问来源于stack exchange,提问作者Kal
相关产品推荐
相关产品推荐

