Annotate a batch of local files: Core

Annotate a batch of local files while online.

Code sample

Ruby

Before trying this sample, follow the Ruby setup instructions in the Vision Quickstart Using Client Libraries. For more information, see the Vision Ruby API reference documentation.

# Instantiate a client
image_annotator_client = Google::Cloud::Vision.image_annotator

# file_path = "resources/kafka.pdf"
content = File.binread file_path
input_config = {
  mime_type: "application/pdf",
  content:   content
}
feature = { type: :DOCUMENT_TEXT_DETECTION }

# The service can process up to 5 pages per document file. Here we specify the first, second, and
# last page of the document to be processed.
request = {
  input_config: input_config,
  features:     [feature],
  pages:        [1, 2, -1]
}

response = image_annotator_client.batch_annotate_files requests: [request]
response.responses[0].responses.each do |image_response|
  display_image_response image_response
end

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser