Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Environment to Use File System Locally and Amazon on Heroku

Tags:

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

like image 227
user663778 Avatar asked Mar 20 '11 20:03

user663778


People also ask

Can Heroku access local files?

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.

Does Heroku provide cloud Storage?

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.

What is S3 Why do you need to use something like this when deploying an application to Heroku?

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.

Can Heroku store static files?

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.


1 Answers

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 
like image 100
juwalter Avatar answered Oct 20 '22 14:10

juwalter