Use Amazon S3, Rackspace Cloud Files, etc. with Opal¶
Opal uses CarrierWave for file uploads, and can easily be configured to store files with third party cloud services such as Amazon S3, Rackspace Cloud Files, Google Storage, and more. This is a great way to run Opal on Cloud servers like Heroku, etc. that prevent you from storing files locally.
Opal automatically looks for a config file located at config/upload.yml. This file defines custom settings for uploading files. If Opal can't find this file, it uses the default in-house storage method that will store uploaded files inside the application directory. If the file does exist, Opal will load in the settings from the config file. Opal also comes with several example config files for S3 and Rackspace that have most of the required settings already set up.
- Note: most of the configuration settings in upload.yml are identical to CarrierWave configuration settings.
Using Opal with Amazon S3 (Simple Storage Service)¶
To use Amazon S3 with Opal, go ahead and copy the S3 example config file to upload.yml.
cp config/upload.yml.s3 config/upload.yml
Next, open up config/upload.yml in your favorite text editor and paste in your account and bucket information (which is found in your Amazon AWS account).
# Example Configuration File for Amazon S3 Uploads :upload: :storage: :fog # storage method: file, fog(for s3 and rackspace cloud files), etc. :fog_credentials: :provider: AWS :aws_access_key_id: xxx :aws_secret_access_key: yyy :region: 'eu-west-1' # optional :fog_directory: path/to/your/bucket # required, this is your bucket #:fog_host: www.example.com #:fog_public: false # optional, defaults to true #:config.fog_attributes = # 'Cache-Control':'max-age=315576000'
That's all there is to it! Restart Opal and start uploading like a crazy person.
Using Opal with Rackspace Cloud Files¶
To use Rackspace Cloud Files with Opal, go ahead and copy the example config file to upload.yml.
cp config/upload.yml.rackspace config/upload.yml
Next, open up config/upload.yml in your favorite text editor and paste in your RackSpace account information.
# Example Configuration File for Rackspace Cloud Files :upload: :storage: :fog # storage method: file, fog(for s3 and rackspace cloud files), etc. :fog_credentials: :provider: Rackspace :rackspace_username: xxx :rackspace_api_key: yyy :fog_directory: path/to/your/directory # required, this is your bucket #:fog_host: "c000000.cdn.rackspacecloud.com"
Save your changes...and...you're done. Restart Opal and go wild!
Mixing and matching storage types¶
Currently, you cannot mix and match storage types with Opal. This means that if you have been uploading files locally, then you decide to switch to Amazon S3, you need to manually upload those local files to your 3rd party account(in this case, your Amazon S3 bucket).