Provides Fog storage for Shrine.

Fog is an abstraction over a variety of cloud storages (e.g. Google Cloud and Dropbox).


gem "shrine-fog", "~> 2.0"
gem "fog-xyz" # Fog gem for the storage you want to use


Require the appropriate Fog gem, and assign the parameters for initializing the storage:

require "shrine/storage/fog"
require "fog/google"

Shrine.storages[:store] =
  provider: "Google",                                    #
  google_storage_access_key_id: "ACCESS_KEY_ID",         # Fog credentials
  google_storage_secret_access_key: "SECRET_ACCESS_KEY", #
  directory: "uploads",

You can also assign a Fog storage object as the :connection:

require "shrine/storage/fog"
require "fog/google"

google =
  provider: "Google",
  google_storage_access_key_id: "ACCESS_KEY_ID",
  google_storage_secret_access_key: "SECRET_ACCESS_KEY",

Shrine.storages[:store] =
  connection: google,
  directory: "uploads",

If both cache and store are a Fog storage, the uploaded file is copied to store instead of reuploaded.


By default shrine-fog will generate signed expiring URLs.

uploaded_file.url("image.jpg") #=> ""

You can modify the URL expiration date via :expires (the default is 3600):

uploaded_file.url("image.jpg", expires: 90) #=> ""

If the files you're uploading are public readable (e.g. you're passing the correct ACL on upload, acl: "publicRead" for fog-google), and you want to generate public URLs, you can pass public: true to #url:

uploaded_file.url("image.jpg", public: true) #=> ""

Any additional URL options will be forwarded directly to the provider's File#url method.

You can use the default_url_options Shrine plugin to set default URL options.

Upload options

Dynamic upload options can be passed via the upload_options plugin:

Shrine.plugin :upload_options, store: { acl: "publicRead" }

You can also specify default upload options on storage initialization: { acl: "publicRead" }, **options)

S3 or Filesystem

If you want to store your files to Amazon S3 or the filesystem, you should use the storages that ship with Shrine (instead of fog-aws or fog-local) as they are much more advanced.

Running tests

Tests use fog-aws, so you'll have to create an .env file with appropriate credentials:

# .env

Afterwards you can run the tests:

$ bundle exec rake test


This gem was inspired by refile-fog.