You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 17:55:58