5

I am trying to upload JPG or PNG images stored in the local file system to Amazon Rekognition on the command line using aws-cli/1.11.175. Images stored in S3 work perfectly fine, but I can't figure out how the CLI call should look like, if the file is stored locally:

# aws rekognition detect-labels --image '???'

The documentation suggests --image "Bytes='...'" and I also understand, that the image should be base64 encoded. However, whatever I try, I end up with the following error message.

An error occurred (InvalidImageFormatException) when calling the DetectLabels
operation: Invalid image encoding

I tried things like this:

# IMAGE=$(base64 --wrap=0 image.jpg)
# aws rekognition detect-labels --image "Bytes='${IMAGE}'"

# base64 --wrap=0 image.png > image.png.b64
# aws rekognition detect-labels --image "Bytes='file:///image.png.b64'"

Can someone provide an example, how to pass an image stored in the file system to Rekognition, without the need to copy it to an S3 bucket first? How should the --image option look like?

fred
  • 61
  • 4
  • The documentation for DetectModerationLabels (http://docs.aws.amazon.com/rekognition/latest/dg/API_DetectModerationLabels.html) says: "If you use the AWS CLI to call Amazon Rekognition operations, passing base64-encoded image bytes is not supported." I'm not sure if that's actually true, but it sounds ominous. You might want to write a simple Python or Node.js script using the relevant AWS SDK as that *can* pass in the byte stream and there's sample code out there (http://docs.aws.amazon.com/rekognition/latest/dg/example4.html). Poor docs here. – jarmod Oct 28 '17 at 23:45
  • This looks like a bug, and a somewhat obvious one, in aws-cli. It takes the input "blob" you give it, and base64-encodes it *again*. The problem is, it doesn't in fact treat the input as a blob. It treats it as a *string* and tries to interpret it as utf8, so you can't actually pass a blob unless by coincidence you happen to be in possession of a blob that just happens to be comprised of entirely valid utf8 characters. Even if you pass JSON, it *still* encodes the `Bytes` value to base64. This is embarrassing because JSON can't even contain a blob without it already being in base64. – Michael - sqlbot Oct 29 '17 at 00:43
  • Have they gotten rid of the ability to pass a video in with your request?It seems like the only options are via S3 or using Kinesis Video. Would love the ability to upload a video or image without the requirement of storing in S3... The link provided in the comment above redirects somewhere else. – Giovanni B Mar 29 '18 at 22:20

1 Answers1

1

This is a known issue and has been reported in October 2017:
https://github.com/aws/aws-cli/issues/2931

It's currently marked as a possible enhancement (as of May 2018).

Michael
  • 645
  • 5
  • 12