CarrierWave and Fog container, S3 and store_dir

I'm trying to figure out how to configure CarrierWave to work with Fog and Amazon S3. On S3, I have a bucket, "bucket1" with the "images" folder. Loads the work perfectly. For example, an image can be uploaded as 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? %> 
+7
source share
2 answers

Try to remove

config.fog_host = 'https://s3.amazonaws.com'

and put instead

storage: fog

in your bootloader. It could be overriding the actual path with the one you provide.

+4
source

Despite the fact that this issue is not directly related to this issue, he believes that the following information is both useful and useful.

If you use non-public links in S3, you can control the TTL of these links using the fog_authenticated_url_expiration configuration fog_authenticated_url_expiration :

 ... config.fog_public = false config.fog_authenticated_url_expiration = 600 # 10 minutes ... 
+1
source

All Articles