Skip to content

Instantly share code, notes, and snippets.

Created December 14, 2018 20:00
What would you like to do?
require "shrine"
require "down"
# Plugins to load for every uploader
Shrine.plugin :activerecord
Shrine.plugin :determine_mime_type
if Rails.env.production?
require "shrine/storage/google_cloud_storage"
shared_options = {
bucket: ENV["GCS_BUCKET"],
default_acl: "publicRead",
object_options: {
cache_control: "public, max-age: 31536000" # 1 year
Shrine.storages = {
cache: "cache", **shared_options),
store: "store", **shared_options),
# Make all URLs public
url_options = Shrine.storages.keys.inject({}) do |hash, storage_key|
hash.update(storage_key => {
public: true,
host: "#{ENV['GCS_BUCKET']}".freeze,
Shrine.plugin :default_url_options, url_options
require "shrine/storage/file_system"
Shrine.storages = {
cache:"public", prefix: "uploads/cache"),
store:"public", prefix: "uploads/store"),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment