Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Created May 7, 2017 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/c42ab12ed96bdf1f1a8767cc3b18cc19 to your computer and use it in GitHub Desktop.
Save ryuheechul/c42ab12ed96bdf1f1a8767cc3b18cc19 to your computer and use it in GitHub Desktop.
Paperclip + fog + Google Cloud Storage

An example code to use GCS instead of S3

# config/initializers/paperclip.rb
if Rails.env.production?
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:url] = ':gcs_domain_url'
Paperclip::Attachment.default_options[:fog_directory] = ENV['GCS_BUCKET_NAME']
end
# config/environments/production.rb
config.paperclip_defaults = {
storage: :fog,
fog_credentials: {
provider: 'Google',
google_project: ENV['GCS_PROJECT'],
google_client_email: ENV['GCS_CLIENT_EMAIL'],
google_json_key_string: Base64.decode64(ENV['GCS_SECRET_JSON_KEY_STRING_BASE64'])
# Google recommend you to use service account instead of HMAC credentials
# You can check other options here -> https://github.com/fog/fog-google#credentials
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment