Textract API restFul ? Which Parameters ?

0

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 年前檢視次數 1359 次
1 個回答
0

Hi,

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

AWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南