Ruby client for Google Cloud Storage

Posted by Vincent Daubry on January 26, 2014

Ruby client for Google Cloud Storage

After using AWS for some years, the Google Cloud Storage client for Ruby feels like stone age :

  • Oudated code sample
  • Overall complexity
  • Spaghetti documentation
  • Client still doesn’t support file download (after 5 years, come on !)

API are everywhere and every single conference repeats the same mantra : “treat developers as customers”, “think about onboarding”.
Either Google is deaf, or they left the startups market to AWS. I wish them good luck competing with Microsoft Azure for the entreprise business.

So enough bitching, if you need to download a file from Google Storage in Ruby, here is a fixed version of their code sample :

require 'google/api_client'
require 'highline/import'
require './oauth_util'

# Constants for use as request parameters.
DEFAULT_BUCKET = 'githubawards'
FILENAME = 'your_file_to_download.txt'

# Creating a new API client and loading the Google Cloud Storage API.
client = => "githubawards", :application_version => "0.1")
storage = client.discovered_api('storage', API_VERSION)

# OAuth authentication.
auth_util =
client.authorization = auth_util.authorize()

result = client.execute(
        :api_method => storage.buckets.get,
        :parameters => { 'bucket' => DEFAULT_BUCKET, 'object' => FILENAME }

access_token = "Bearer "+result.request.authorization.access_token

Net::HTTP.start(, url.port) do |http|
  request = url.request_uri
  request.add_field("Authorization", access_token)

  http.request request do |response|
    open FILENAME, 'w' do |io|
      response.read_body do |chunk|
        io.write chunk

You can checkout the full project here