Skip to content

Commit

Permalink
Make it easier to use Cloudinary as a storage option for ActiveStorage
Browse files Browse the repository at this point in the history
This makes it easier to use Cloudindary as the backend service for
ActiveStorage. From a functional perspective this works very much like
the S3 service option. ActiveStorage is still in control of files, but
it sends them through to Cloudinary for storage and delivery.

Partial fix for : #1617
  • Loading branch information
jagthedrummer committed Nov 14, 2024
1 parent cc7f11c commit aabd831
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@
# configuration right now, i'm making them the default here as well.
config.action_mailbox.ingress = :mailgun

if (ENV["AWS_ACCESS_KEY_ID"] || ENV["BUCKETEER_AWS_ACCESS_KEY_ID"]).present?
config.active_storage.service = :amazon
elsif ENV["CLOUDINARY_URL"].present?
config.active_storage.service = :cloudinary
else
config.active_storage.service = :local
end

# ✅ YOUR APPLICATION'S CONFIGURATION
# If you need to customize your application's configuration, this is the place to do it. This helps avoid merge
# conflicts in the future when Rails or Bullet Train update their own default settings.
Expand Down
2 changes: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@

if (ENV["AWS_ACCESS_KEY_ID"] || ENV["BUCKETEER_AWS_ACCESS_KEY_ID"]).present?
config.active_storage.service = :amazon
elsif ENV["CLOUDINARY_URL"].present?
config.active_storage.service = :cloudinary
else
puts "WARNING! : We didn't find an active_storage.service configured so we're falling back to the local store, but it's A VERY BAD IDEA to rely on it in production unless you know what you're doing."
config.active_storage.service = :local
Expand Down
3 changes: 3 additions & 0 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ amazon:
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] || ENV['BUCKETEER_AWS_SECRET_ACCESS_KEY'] %>
bucket: <%= ENV['AWS_S3_BUCKET'] || ENV['BUCKETEER_BUCKET_NAME'] %>
region: <%= ENV['AWS_S3_REGION'] || ENV['BUCKETEER_AWS_REGION'] %>

cloudinary:
service: Cloudinary

0 comments on commit aabd831

Please sign in to comment.