I am not sure how to configure the environment such that Carrier Wave will use the local file storage when running the app locally (development) and s3 after i load to heroku (production)
in Development storage :file
in Production storage :s3
Heroku has an “ephemeral” hard drive, this means that you can write files to disk, but those files will not persist after the application is restarted. By default Active Storage uses a :local storage option, which uses the local file system to store any uploaded files.
Table of Contents. Felix Cloud Storage is an Amazon S3-based cloud storage add-ons, dedicated to providing Heroku users with simple and efficient storage services. No need to sign up for a separate Amazon account in order to use Felix Cloud Storage, Felix will automatically generate access credentials for you.
Amazon Simple Storage Service (S3) is a durable and available store, ideal for storing application content like media files, static assets, and user uploads. Storing static files elsewhere is crucial for Heroku apps since dynos have an ephemeral filesystem.
To answer your question, Heroku's "ephemeral filesystem" will not serve as a storage for static uploads. Heroku is an app server, period. You have to plug into data storage elsewhere. Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code.
Either model, or you can set it globally. Have a look at the readme for v0.5.2 (current gem) at https://github.com/jnicklas/carrierwave/tree/v0.5.2
Near the bottom, there are some instructions for configuring the test environment. Use the same approach to use different configurations for "development" and "production", e.g. add a file "carrierwave.rb" to "config/initialisers" and add the configuration code
if Rails.env.test? or Rails.env.cucumber? CarrierWave.configure do |config| config.storage = :file config.enable_processing = false end end
and for development
if Rails.env.development? CarrierWave.configure do |config| config.storage = :file end end
and production
if Rails.env.production? CarrierWave.configure do |config| config.storage = :s3 end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With