Low commit activity in last 3 years
A slimmer alternative to using Fog for Google Cloud Storage support in Carrierwave. Heavily inspired from carrierwave-aws
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.12
>= 0.10.3
>= 12.3.3
~> 3.0
~> 1.0.0

Runtime

 Project Readme

Carrierwave Google Storage

Build Status Code Climate Gem Version

Use the official google-cloud gem by Google for Google Cloud Storage, instead of Fog.

  • No need to activate Interoperable Access on your project.
  • Rely on Google's preferred authentication mechanism. ie: Service Accounts.

Installation

Add this line to your application's Gemfile:

gem 'privy-carrierwave-google-storage'

Rails Compatibility:

  • Rails 4 and 5.

Usage

In config/initializers/carrierwave.rb add the following initialization code:

CarrierWave.configure do |config|
  config.storage                             = :gcloud
  config.gcloud_bucket                       = 'your-bucket-name'
  config.gcloud_bucket_is_public             = true
  config.gcloud_authenticated_url_expiration = 600
  config.gcloud_content_disposition          = 'attachment' // or you can skip this

  config.gcloud_attributes = {
    expires: 600
  }

  config.gcloud_credentials = {
    gcloud_project: 'gcp-project-name',
    gcloud_keyfile: 'path-to-gcp-keyfile.json'
  }
end

Then, in your Uploader classes:

class FileUploader < CarrierWave::Uploader::Base
   storage :gcloud
end

How to get the Keyfile?

To generate a new keyfile, perform the following steps:

  • Go to Cloud Console > API Manager > Credentials
  • Click Create Credentials > Service Account Key
  • Service Account > New Service Account
  • Give any name for "Service Account Name"
  • Set Key type to JSON
  • Click "Create"

Here's a quick GIF for those who are visual like myself:

Contributing

Environment Variables and such

You should have access to a Google Cloud Platform account, as you'll need the keyfile and a project ID in order to contribute to the development of this gem. You'll need the the following files:

  • .gcp-keyfile.json (sample file provided: .gcp-keyfile.sample.json)
  • .env (sample file provided: .env.sample)

If you have any questions, please feel free to open up issues and/or PR's. Contributions are welcomed.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

You get extra attention, if your PR includes specs/tests.

  • Fork or clone the project.
  • Create your feature branch ($ git checkout -b my-new-feature)
  • Install the dependencies by doing: $ bundle install in the project directory.
  • Add your bug fixes or new feature code.
  • New features should include new specs/tests.
  • Bug fixes should ideally include exposing specs/tests.
  • Commit your changes ($ git commit -am 'Add some feature')
  • Push to the branch ($ git push origin my-new-feature)
  • Open your Pull Request!

License

Copyright (c) 2016 Jasdeep Singh (Metaware Labs Inc)

The gem is available as open source under the terms of the MIT License.