CarrierWave and Fog, S3 bucket and store_dir configuration
10,805
Try removing the
config.fog_host = 'https://s3.amazonaws.com'
configuration and instead put
storage :fog
in your uploader. It might be overriding the actual path with the one you're providing.
Author by
Jonathan Mui
Updated on June 12, 2022Comments
-
Jonathan Mui almost 2 years
I'm trying to figure out how to setup CarrierWave to work with Fog and Amazon S3. On S3, I have a bucket, "bucket1" with folder "images". Uploads work fine. For example, an image might get uploaded to something of the form https://s3.amazonaws.com/bucket1/images/picture/pic1.jpg. However, in the show view, when I call the image_url helper, I get https://s3.amazonaws.com/images/picture/pic1.jpg. What am I missing here?
#config/initializers/carrierwave.rb CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', :aws_access_key_id => 'aws_key', :aws_secret_access_key => 'aws_secret' } config.fog_directory = 'bucket1' config.fog_host = 'https://s3.amazonaws.com' config.fog_public = true config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} end #app/uploader/image_uploader.rb def store_dir "images/#{model.class.to_s.underscore}" end #app/views/pictures/show.html.erb <%= image_tag @picture.image_url if @picture.image? %>