Granular "public" settings for uploaded files using Fog and Carrierwave

I am creating a rails application that allows an administrator to upload photos that can be publicly displayed. For the loading / storage process, I use the Carrierwave gem along with Fog and S3 pearls. The problem is that in order for this to work, I have to make each file uploaded to s3 bucket public. Is there a way to make files public / private by file? In addition, if this dimension for each file is possible, can it expand to image versions (created by automatically resizing Carrierwave)?

Currently, I have the following line in the carrier initializer:

  config.fog_public = true
+5
source share
2 answers

Actually, he’s just dead in Carrierwave.

You can do it:

class PrivateUploader < StandardUploader  

  @fog_public = false

Or (untested, but should work fine):

class PrivateUploader < StandardUploader  


  def fog_public
    if local_condition
      true
    else
      false
    end
  end

:-)

I have not tried DragonFly, but now that several problems have been fixed in the last 2 months with Carrierwave, this is far superior to everything I've seen. Insanely flexible.

// matte

+7
source

You just need to force the uploader class to override the base class. I also tore my hair ... :( This worked for me:

Using Carrierwave 0.8.0 (May 2013) / app / uploaders / whatever _uploader.rb

class WhateverUploader < CarrierWave::Uploader::Base
  def fog_public
    true # or false
  end
end
+5
source

All Articles