Annotate a batch of files in Cloud Storage: Core

Annotate a batch of files in Cloud Storage 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

# storage_uri = "gs://cloud-samples-data/vision/document_understanding/kafka.pdf"
input_config = {
  gcs_source: { uri: storage_uri },
  mime_type:  "application/pdf"
}
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_annotation_response image_response
end

What's next

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