Reputation: 178
I'm using Carrierwave in my Rails app to handle image uploads. When I configure the uploader to store the files locally, everything works great. The problem comes when I ask to upload to Rackspace's Cloud Files service. The upload works great, I can see the files in my control panel. The issue is that Carrierwave returns a URL on the uploader as if the file were stored locally. ie: @foo.uploader.url
looks like /User/bar/Code/app/public/uploads/yeah.jpeg
instead of http://cloudcloud.com/yeah.jpg
.
Where am I going wrong?
# config/initializers/carrier_wave.rb
CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
:provider => 'Rackspace',
:rackspace_username => 'foo',
:rackspace_api_key => '0f0f0f0f0f0f0f'
}
config.fog_directory = 'development-images'
end
# app/uploaders/foo_uploader.rb
class FooUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Upvotes: 3
Views: 1239
Reputation: 146
I took a look at my own code for the Rackspace uploader and the only difference I can see is that I set the fog_host to the CDN url like so:
config.fog_host = "http:/something.rackcdn.com"
Upvotes: 4