Textract API restFul ? Which Parameters ?


Is the textract service usable via Rest API?

If so what are the exact parameters to provide on the REST request?

And what are the exact parameters to provide in the elaboration of the canonical request.

For my part I tried the following code:

request_HTTP is restRequest

request_HTTP..URL = URLEncode("https://textract.eu-west-3.amazonaws.com")

request_HTTP..Method = httpPost

request_HTTP.ContentType = "application/x-amz-json-1.1"

request_HTTP.Content = { "Document": { "Bytes":"xxxxx" } } xxxx is the binary buffer of a file = Hash(NameFile.jpg)

requete_HTTP..Header["authorization"] = AWS4-HMAC-SHA256 Credential=myAWSAccessKey/20220411/eu-west-3/textract/aws4_request,SignedHeaders=content-type;host;x-amz-date,Signature=55fbb067c5ea5612146f7252b341fa22473338b6703cf1ad6703cf1

request_HTTP..Header["x-amz-algorithm"] = "AWS4-HMAC-SHA256"

request_HTTP..Header["x-amz-credential"] =myAWSAccessKey/20220411T093952Z/eu-west-3/textract/aws4_request

request_HTTP..Header["x-amz-date"] = "20220411T093952Z"

requete_HTTP..Header["x-amz-target"] = "Text.AnalyzeExpense"

for the canonical request allowing to create the chain to be signed the following code:

POST\n/\nAction=AnalyzeExpense\ncontent-Type:application/x-amz-json-1.1; charset=utf-8\nhost:textract.amazonaws.com\nx-amz-date:20220411T122110Z\ncontent-type;host;x-amz-date\nbufHash_RequestPayload

or bufHash_RequestPayload=LowerCase(Hex(Hash NameFile.jpg))= 14a085e370add4de92a3509c7891c27c9373b37b5ba83c3e395a8570303658c3

In the end I have the answer: "__type":"InvalidSignatureException", "message":"The request signature we calculated does not match the signature you provided

I certainly forgot something in advance thank you for your help

nb: x-amzn-RequestId: 7877cc30-b196-40dd-8e3d-ba6c9dcf6200

질문됨 2년 전1534회 조회
1개 답변


The easiest way to consume the APIs is through the SDKs (for instance in python : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/textract.html)

But if you need to implement the REST calls on your own, you can look at the API documentation here : https://docs.aws.amazon.com/textract/latest/dg/API_Operations.html

Here is the reference to create the Sigv4 canonical request: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠