For those who want to use Amazon Textract, here is some code that can be executed.
There wasn't much Ruby sample code that used Amazon Textract in the world, so I wrote it. It's not useful code, but I think it can be used as a reference for those who want to use Amazon Textract in Ruby for the time being.
--Amazon Textract is a paid service. If you just touch it, I think it will fit in the free frame, but please be careful not to overdo it. --As of January 2, 2021, Amazon Textract cannot read Japanese.
We have designated Northern Virginia as the region because it is not yet available in the Tokyo region (ap-northeast-1). If this is omitted, the default region will be applied, and if the default is ap-northeast-1, an error will occur and it cannot be used.
client = Aws::Textract::Client.new(region: 'us-east-1')
See here for AWS credentials.
Read the text by referring to the Amazon Textract Client Class API Reference.
The API reference also describes how to handle files on the S3 bucket, but since the information about bytes
was thin, I wrote about bytes
in this article.
detected = client.detect_document_text(document: { bytes: URI.open('sample.png').read })
--API Reference for Amazon Textract Client Class -How to set AWS authentication information to refer to programmatically with AWS CLI
Recommended Posts