Public URL with Fog and Amazon S3

Versions of all RubyGems. I use Ruby on Rails 3.1.3, Ruby 1.9.2, CarrierWave 0.5.8 and Fog 1.1.2.

I use CarrierWave RubyGem to upload images and Fog RubyGem to upload an Amazon S3 file .

In my CarrierWave initialization file, I have:

CarrierWave.configure do |config| config.fog_credentials = { provider: 'AWS', aws_access_key_id: 'xxx', aws_secret_access_key: 'xxx' } if Rails.env.production? config.fog_directory = 'bucket1' elsif Rails.env.development? config.fog_directory = 'bucket2' else config.fog_directory = 'bucket3' end config.fog_public = false config.fog_authenticated_url_expiration = 60 end 

I have an uploader file:

 class PageAttachmentUploader < CarrierWave::Uploader::Base CarrierWave.configure do |config| if Rails.env.development? || Rails.env.development? || Rails.env.production? config.fog_public = true end end storage :fog end 

I have two uploader files. I want one of them to be closed and the other to be public.

I am trying to overwrite CarrierWave configuration when calling the PageAttachmentUploader method and set the URL for the public. This works like a charm on a local computer, but it does not work at the stage of staging, sandboxing and production.

I changed config.fog_public = true in the CarrierWave interpreter. Even this does not work in the sandbox. How to fix this problem?

+4
source share
2 answers

No, you should not use CarrierWave.configure directly in your bootloaders, as it will change the default configuration for all bootloaders, and not just for each user.

I don’t know if this is the best solution, but you can change the default fog configuration directly by setting the class methods in your loaders as follows:

 class ImageUploader < CarrierWave::Uploader::Base storage :fog def self.fog_public true # or false end end 
+23
source

Actually, the best way (I found) is to do the following:

 class ImageUploader < CarrierWave::Uploader::Base storage :fog configure do |c| c.fog_public = true # or false end end 

It looks like CarrierWave style to do it this way.

+1
source

Source: https://habr.com/ru/post/1402943/


All Articles