Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload an image to AWS Rekognition using command line tools (AWS CLI)

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?

like image 877
fred Avatar asked Nov 08 '22 15:11

fred


1 Answers

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).

like image 57
Michael Avatar answered Nov 15 '22 07:11

Michael