Skip to content

Instantly share code, notes, and snippets.

@dvodvo
Last active January 20, 2022 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvodvo/9b69f7be345fc13ba2572a0f865097f7 to your computer and use it in GitHub Desktop.
Save dvodvo/9b69f7be345fc13ba2572a0f865097f7 to your computer and use it in GitHub Desktop.
Carrierwave && carrierwave-aws initializer for connecting to DO Spaces
# uploads.rb
CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = 'my-bucket-s-name' # name of bucket, no FQDN
config.aws_acl = 'private'
# Optionally define an asset host for configurations that are fronted by a
# content host, such as CloudFront.
# config.asset_host = 'http://example.com'
# The maximum period for authenticated_urls is only 7 days.
config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
# Set custom options such as cache control to leverage browser caching.
# You can use either a static Hash or a Proc.
config.aws_attributes = -> { {
expires: 1.week.from_now.httpdate,
cache_control: 'max-age=604800'
} }
config.aws_credentials = {
access_key_id: Rails.application.credentials.dig(:digitalocean, :access_key),
secret_access_key: Rails.application.credentials.dig(:digitalocean, :secret),
endpoint: 'https://fra1.digitaloceanspaces.com', # endpoint is the option of '-aws' for connecting to 3rd party services, state as provided by DO
region: 'fra1', # Required (not tested without though
stub_responses: Rails.env.test? # Optional, avoid hitting S3 actual during tests
}
# Optional: Signing of download urls, e.g. for serving private content through
# CloudFront. Be sure you have the `cloudfront-signer` gem installed and
# configured:
# config.aws_signer = -> (unsigned_url, options) do
# Aws::CF::Signer.sign_url(unsigned_url, options)
# end
end
environments/development.rb
config.active_storage.service = :digitalocean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment