forked from carrierwaveuploader/carrierwave
-
Notifications
You must be signed in to change notification settings - Fork 2
How to: Store private public uploads in different Cloud Files Containers with Fog
abmxer edited this page Apr 9, 2013
·
3 revisions
When using Cloud Files Containers, you cannot set individual file permissions - a container and its files are either public (delivered over CDN), or private.
When using Fog in your Uploader, you can specify a different container from the configured defaults by simply calling fog_host
and fog_directory
directly in your uploader.
For example, given a simple web store selling documents, the uploaded document files that people can buy should be private:
# config/initializers/carrier_wave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'Rackspace',
:rackspace_username => 'xxxxxxxxx',
:rackspace_api_key => 'yyyyyyyyy',
:rackspace_servicenet => Rails.env.production?
}
config.fog_directory = 'my_private_container'
config.fog_public = false
end
# app/uploaders/document_uploader.rb
class DocumentUploader < CarrierWave::Uploader::Base
# Uploader will use the private container configured in config/initializer/carrier_wave.rb
storage :fog
end
Whilst the uploaded screenshots to be used on the product pages should be publicly available and delivered via CDN:
# app/uploaders/screenshot_uploader.rb
class ScreenshotUploader < CarrierWave::Uploader::Base
storage :fog
# Configure uploads to be stored in a public Cloud Files container
def fog_directory
'my_public_container'
end
# Configure uploads to be delivered over Rackspace CDN
def assets_host
"c000000.cdn.rackspacecloud.com"
end
end