aws-beam/aws-elixir

Error calling textractor

CharlesOkwuagwu opened this issue ยท 3 comments

Hi,

I get this error, kindly guide me if I'm calling it wrong.

{:error, {:unexpected_response, %{body: "{\"__type\":\"InvalidParameterException\",\"Message\":\"Request has invalid parameters\"}", headers: [{"x-amzn-RequestId", "94407fa7-e7b2-4d83-9bd3-a6b32d01184e"}, {"Content-Type", "application/x-amz-json-1.1"}, {"Content-Length", "81"}, {"Date", "Wed, 19 Apr 2023 14:54:21 GMT"}, {"Connection", "close"}], status_code: 400}}}

def ocr(file) do
data = File.read!(file) |> :base64.encode_to_string()

    client =
      AWS.Client.create(
        "xxxxxxxxxxxxxx",
        "xxxxxxxxxxx",
        "eu-west-1"
      )

    req = %{Document: %{Bytes: "#{data}"}}
    AWS.Textract.analyze_document(client, req)
  end

@CharlesOkwuagwu I haven't used this API myself but judging by their docs a FeatureTypes element is Required: Yes so I presume that is what's missing from your req.

Try adding a list of FeatureTypes that you're after ๐Ÿ‘ Allowed values are: TABLES | FORMS | QUERIES | SIGNATURES

For reference the full API docs are here: https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeDocument.html

solved

  def ocr(file) do
    data = File.read!(file) |> Base.encode64()

    AWS.Client.create(
      "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "eu-west-1"
    )
    |> AWS.Textract.analyze_document(%{
      "Document" => %{"Bytes" => data},
      "FeatureTypes" => ["TABLES"]
    })
  end

Awesome!