Visitar URL original
How to set correct url endpoint if other than 'us' ? · Issue #23426 · googleapis/google-cloud-ruby · GitHub
Skip to content

How to set correct url endpoint if other than 'us' ? #23426

Description

@ionosphere

Hi,

I think, there a parmater missing in config to set correctly the api endpoint url.

If we have a server from 'EU', there's no way to adapt the endpoint.

https://github.com/googleapis/google-cloud-ruby/blob/1f1b9cc2fb096cd9403b6b8baf370379420f34cd/google-cloud-document_ai/lib/google/cloud/document_ai.rb#L32C1-L33C1

Activity

  1. meredithslota commented on Oct 10, 2023

    @meredithslota
    Contributor

    Hi there — the code you linked describes the default for DocumentAI: https://cloud.google.com/document-ai/docs/regions but it's configurable. The DocAI Quickstart shows an example of configuring location: https://github.com/googleapis/google-cloud-ruby/blob/main/google-cloud-document_ai/samples/quickstart.rb Please take a look! Thanks!

  2. ionosphere commented on Oct 10, 2023

    @ionosphere
    Author

    Thanks @meredithslota but i am not sure it works outside US

    When we look at the code and the attributes, we have "documentai.googleapis.com" as endpoint evenif we have 'eu' as location parameter

    client = Google::Cloud::DocumentAI.document_processor_service
    
    # adding an ENV with correct endpoint if you are not in US
    # example in .env  DOC_AI_ENDPOINT='eu-documentai.googleapis.com'
    
    ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.configure do |config|
       config.endpoint = ENV['DOC_AI_ENDPOINT']
    end

    Another thinks, according to the doc, we have to encode in Base64

    # Read the bytes into memory and encode in Base64
      bin_file = File.binread file_path
      content = Base64.strict_encode64(bin_file)

    After that, i ve always have an error
    Google::Cloud::InvalidArgumentError: 3:Unsupported input file format..

  3. dazuma commented on Oct 12, 2023

    @dazuma
    Contributor

    @ionosphere Try setting the config.endpoint before creating the client. The configuration is used by the client object constructor, so setting it after the client is created, as in the code snippet above, will have no effect.

  4. ionosphere commented on Oct 18, 2023

    @ionosphere
    Author

    Hi there,
    @dazuma I've got the same error.

    The client object looks good but i am not sure why we have 2 attributes @access_token ??

    #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client:0x0000561e7d31fa50
     @config=
      #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration:0x0000561e7e0514a8
       @parent_config=
        #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration:0x0000561e7d080308
         @endpoint="eu-documentai.googleapis.com",
         @parent_config=,
         @rpcs=
          #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration::Rpcs:0x0000561e7d0802e0
           @batch_process_documents=#<Gapic::Config::Method:0x0000561e7d080268 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>,
           @process_document=#<Gapic::Config::Method:0x0000561e7d0802b8 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>,
           @review_document=#<Gapic::Config::Method:0x0000561e7d080240 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>>>,
       @rpcs=
        #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration::Rpcs:0x0000561e72bfbfa8
         @batch_process_documents=
          #<Gapic::Config::Method:0x0000561e72bfbdf0
           @parent_config=#<Gapic::Config::Method:0x0000561e7d080268 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>>,
         @process_document=
          #<Gapic::Config::Method:0x0000561e72bfbf80
           @parent_config=#<Gapic::Config::Method:0x0000561e7d0802b8 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>>,
         @review_document=
          #<Gapic::Config::Method:0x0000561e72bfbcb0
           @parent_config=#<Gapic::Config::Method:0x0000561e7d080240 @retry_policy={:initial_delay=>0.1, :max_delay=>60.0, :multiplier=>1.3, :retry_codes=>[4, 14]}, @timeout=120.0>>>>,
     @document_processor_service_stub=
      #<Gapic::ServiceStub:0x0000561e7f04c150
       @grpc_stub=
        #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Stub:0x0000561e7f053e50
         @ch=#<GRPC::Core::Channel:0x0000561e7f053b30>,
         @host="eu-documentai.googleapis.com",
         @interceptors=#<GRPC::InterceptorRegistry:0x0000561e7f053928 @interceptors=[]>,
         @propagate_mask=nil,
         @timeout=1970-01-01 00:59:59 +0100>>,
     @operations_client=
      #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Operations:0x0000561e7f04b110
       @config=
        #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Operations::Configuration:0x0000561e7f04ce70
         @credentials=
          #<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Credentials:0x0000561e7e81c598
           @client=
            #<Google::Auth::ServiceAccountCredentials:0x0000561e7e81cd18
             @access_token=
             @access_token=
              "XXXXXXXXXXXXXXXXXXXXXXX",
             @access_type=:offline,
             @additional_parameters={},
             @audience="https://oauth2.googleapis.com/token",
             @authorization_uri=nil,
             @client_id=nil,
             @client_secret=nil,
             @code=nil,
             @connection_info=nil,
             @enable_self_signed_jwt=false,
             @expires_at=2023-10-18 14:22:08 +0200,
             @expiry=60,
             @extension_parameters={},
             @grant_type=nil,
             @granted_scopes=nil,
             @issued_at=2023-10-18 13:22:09 +0200,
             @issuer="XXXXXXXXXXXXX@XXXXXXXXXXX.gserviceaccount.com",
             @password=nil,
             @principal=nil,
             @project_id="ekylibre",
             @quota_project_id=nil,
             @redirect_uri=nil,
             @refresh_token=nil,
             @scope=["https://www.googleapis.com/auth/cloud-platform"],
             @signing_key=#<OpenSSL::PKey::RSA:XXXXXXXXXXXXXX>,
             @state=nil,
             @target_audience=nil,
             @token_credential_uri=#<Addressable::URI:0x2b0f3f40e524 URI:https://oauth2.googleapis.com/token>,
             @username=nil>,
           @env_vars=nil,
           @paths=nil,
           @project_id="XXXXXXXXX",
           @quota_project_id=nil,
           @scope=nil>,
         @endpoint="eu-documentai.googleapis.com",
         @parent_config=#<Google::Cloud::DocumentAI::V1::DocumentProcessorService::Operations::Configuration:0x0000561e7f04cec0>>,
       @operations_stub=
        #<Gapic::ServiceStub:0x0000561e7f04cbc8
         @grpc_stub=
          #<Google::Longrunning::Operations::Stub:0x0000561e7f04c790
           @ch=#<GRPC::Core::Channel:0x0000561e7f04c510>,
           @host="eu-documentai.googleapis.com",
           @interceptors=#<GRPC::InterceptorRegistry:0x0000561e7f04c498 @interceptors=[]>,
           @propagate_mask=nil,
           @timeout=1970-01-01 00:59:59 +0100>>,
       @quota_project_id=nil>,
     @quota_project_id=nil>

    Anyway, when building the request

    request = Google::Cloud::DocumentAI::V1::ProcessRequest.new(
            skip_human_review: true,
            name: @name,
            raw_document: {
              content: content,
              mime_type: document.file_content_type
            }
          )

    When encoding in Base64

    we have someting like

    <Google::Cloud::DocumentAI::V1::ProcessRequest: name: "projects/602996917882/locations/eu/processors/fed5d64a222362ff", skip_human_review: true, raw_document: <Google::Cloud::DocumentAI::V1::RawDocument: content: "JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9Db....." mime_type: "application/pdf">>

    response

    Google::Cloud::InvalidArgumentError: 3:Unsupported input file format.. debug_error_string:{UNKNOWN:Error received from peer ipv6:XXXXXXXXXXXXXXXX:443 {created_time:"2023-10-18T13:23:38.811535761+02:00", grpc_status:3, grpc_message:"Unsupported input file format."}}

    When just binread the doc

    <Google::Cloud::DocumentAI::V1::ProcessRequest: name: "projects/602996917882/locations/eu/processors/fed5d64a222362ff", skip_human_review: true, raw_document: <Google::Cloud::DocumentAI::V1::RawDocument: content: ""%PDF-1.4
    %����
    4 0 obj
    <</ColorSpace/DeviceGray/Subtype/Image/Height 264/Filter/FlateDecode/Type/XObject/Width 474/Length 12198/BitsPerComponent 8>>stream
    x��};��:s���\���"" mime_type: "application/pdf">>

    response

    output error: #<ArgumentError: invalid byte sequence in UTF-8>

  5. ionosphere commented on Oct 22, 2023

    @ionosphere
    Author

    Hi,

    Anybody has comment about that ?

  6. nshganesh commented on May 24, 2024

    @nshganesh

    @ionosphere were you able to find a workaround on this issue?

  7. amanda-tarafa commented on Oct 9, 2026

    @amanda-tarafa

    Closing because of over 2 years of inactivity. Leave a comment if you are still experiencing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions