Skip to content
Extends Paperclip with Google Cloud Storage
Ruby Shell
Branch: master
Clone or download
Latest commit c6875cb Jan 14, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin initial commit Jun 23, 2017
lib version 0.2.0 Jan 14, 2018
test initial commit Jun 23, 2017
Gemfile version 0.2.0 Jan 14, 2018
Rakefile initial commit Jun 23, 2017


paperclip-gcs is a Paperclip storage driver for storing files in a Google Cloud Storage.


Add this line to your application's Gemfile:

gem 'paperclip-gcs'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paperclip-gcs


The GCS storage engine has been developed to work as similarly to S3 storage configuration as is possible. This gem can be configured in a Paperclip initializer as follows:

Paperclip::Attachment.default_options[:storage] = :gcs
Paperclip::Attachment.default_options[:gcs_bucket] = "your-bucket"
Paperclip::Attachment.default_options[:url] = ":gcs_path_url"
Paperclip::Attachment.default_options[:path] = ":class/:attachment/:id/:style/:filename"
Paperclip::Attachment.default_options[:gcs_credentials] = {
    project: ENV["GCS_PROJECT"],
    keyfile: ENV["GCS_KEYFILE"],

Or, at the level of the model such as in the following example:

has_attached_file :avatar,
  storage: :gcs,
  gcs_bucket: "your-bucket",
  gcs_credentials: {
    project: "your-project",
    keyfile: "path/to/your/keyfile",

See also



GCS bucket name.


You can provide the project and credential information to connect to the Storage service, or if you are running on Google Compute Engine this configuration is taken care of for you.


Project identifier for GCS. Project are discovered in the following order:

  • Specify project in project
  • Discover project in environment variables STORAGE_PROJECT, GOOGLE_CLOUD_PROJECT, GCLOUD_PROJECT
  • Discover GCE credentials


Path of GCS service account credentials JSON file. Credentials are discovered in the following order:

  • Specify credentials path in keyfile
  • Discover credentials path in environment variables GOOGLE_CLOUD_KEYFILE, GCLOUD_KEYFILE
  • Discover credentials JSON in environment variables GOOGLE_CLOUD_KEYFILE_JSON, GCLOUD_KEYFILE_JSON
  • Discover credentials file in the Cloud SDK's path
  • Discover GCE credentials

bucket (optional)

Here you can specify the GCS bucket name. If gcs_bucket also has a bucket specification, the value of gcs_bucket will be used.



Number of times to retry requests on server error.


Default timeout to use in requests.


The protocol for the URLs generated to your GCS assets. Can be either 'http', 'https', or an empty string to generate protocol-relative URLs. Defaults to empty string.


The fully-qualified domain name (FQDN) that is the alias to the GCS domain of your bucket. Used with the :gcs_alias_url url interpolation. See the link in the url entry for more information about GCS domains and buckets.


If you are using a bucket in a custom domain, write host_name.


You can also choose to provide your own AES-256 key for server-side encryption. See also Customer-supplied encryption keys.


User provided web-safe keys and arbitrary string values that will returned with requests for the file as "x-goog-meta-" response headers.

You can set metadata on a per style bases by doing the following:

gcs_metadata: {
  thumb: { "foo" => "bar" }

Or globally:

gcs_metadata: { "foo" => "bar" }


Permission for the object in GCS. Acceptable values are:

  • auth_read - File owner gets OWNER access, and allAuthenticatedUsers get READER access.
  • owner_full - File owner gets OWNER access, and project team owners get OWNER access.
  • owner_read - File owner gets OWNER access, and project team owners get READER access.
  • private - File owner gets OWNER access.
  • project_private - File owner gets OWNER access, and project team members get access according to their roles.
  • public_read - File owner gets OWNER access, and allUsers get READER access.

Default is nil (bucket default object ACL). See also official document.

You can set permissions on a per style bases by doing the following:

gcs_permissions: {
  thumb: :public_read

Or globally:

gcs_permissions: :public_read


Storage class of the file. Acceptable values are:

  • dra - Durable Reduced Availability
  • nearline - Nearline Storage
  • coldline - Coldline Storage
  • multi_regional - Multi-Regional Storage
  • regional - Regional Storage
  • standard - Standard Storage

You can set storage class on a per style bases by doing the following:

gcs_storage_class: {
  thumb: :multi_regional

Or globally:

gcs_storage_class: :multi_regional


The Cache-Control metadata allows you to control whether and for how long browser and Internet caches are allowed to cache your objects.











After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at

You can’t perform that action at this time.