Home > Net >  AWS Rekognition not recognizing image as bytes
AWS Rekognition not recognizing image as bytes

Time:01-29

Getting error in AWS

InvalidParameterException: Requested image should either contain bytes or s3 object.

console.log(imageBuffer) shows enter image description here

Code that passes the image to AWS function

  const moderateEachPic = async (image) => {
    let imageBuffer;
    imageBuffer = new Uint8Array(await image.arrayBuffer())
    // moderate image using AWS Rekognition
    console.log(imageBuffer)
    await verifyImage (imageBuffer).then((res) => {
     ....
    })
  }

This is the function to call AWS Rekognition

var rekognition = new RekognitionClient({
  credentials: creds,
  region: region,
})

export async function verifyImage (image ) {
  console.log(image)
  const params = {
    Image:{
      image
   },
   Attributes: ['ALL']
  };

  const command = new DetectFacesCommand(params);

CodePudding user response:

Image per the AWS SDK has two properties, Bytes and S3Object. You have to set those appropriately in order to have your example work.

I can't get your sample to run locally, but, try this:

var rekognition = new RekognitionClient({
  credentials: creds,
  region: region,
})

export async function verifyImage (image ) {
  console.log(image)
  const params = {
    Image: {
        Bytes: image,
    },
   },
   Attributes: ['ALL']
  };

  const command = new DetectFacesCommand(params);
  • Related