Different S3 permissions for different versions

554 views
Skip to first unread message

krismartin

unread,
Feb 15, 2011, 8:16:02 AM2/15/11
to carrierwave
I am using CarrierWave with S3 storage to store images. I need to set
different access control for different versions of the image. The
original image need to be kept "private" and the different versions
can be public ("public-read").

I have successfully achieved this by getting down to the underlying
fog gem and change the S3 ACL after the files have been uploaded to S3
using the after_create callback on the model.

Is there an easy way to do this in the uploader?

Jonas Nicklas

unread,
Feb 15, 2011, 8:47:18 AM2/15/11
to carri...@googlegroups.com
I think you should be able to do this:

class MyUploader < CarrierWave::Uploader::Base
s3_access_policy :public_read

version :thumb do
s3_access_policy :public
end
end

or something along those lines.

/Jonas

> --
> You received this message because you are subscribed to the Google Groups "carrierwave" group.
> To post to this group, send email to carri...@googlegroups.com.
> To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.
>
>

krismartin

unread,
Feb 15, 2011, 8:35:54 PM2/15/11
to carrierwave
That works! Why didn't I think of that :)

So what I did was I make the default s3_access_policy in the uploader
as "private" (since the original need to be kept private) and override
the acl for each version as "public-read"

clas MyUploader < CarrierWave::Uploader::Base
s3_access_policy "private"

version :thumb do
s3_access_policy "public-read"
end
end

Thanks Jonas!

deepak kumar

unread,
Feb 12, 2013, 7:26:28 AM2/12/13
to carri...@googlegroups.com
I resolved this issue by setting @fog_public = false in my uploader

class SampleUploader < Carrierwave::Uploader::Base
    @fog_public = false
end

On Monday, 11 February 2013 18:18:02 UTC+5:30, deepak kumar wrote:
@jnicklas That method sounds good, But I for me when I do the same I get the following error 
 
undefined method `s3_access_policy'

I checked the code of fog and carrierwave but couldn't find an example or comment doing this. 

Yassin Chelabi

unread,
Oct 29, 2015, 1:51:18 PM10/29/15
to carrierwave
FYI ;)

  version :":thumb", :if => :image? do
    process :resize_and_pad => [40, 40, "white"]
    # when version is called, it initisialize a new class so
    # we must override fog_public to get public url on this version
    self.define_singleton_method(:fog_public) { true }
  end
Reply all
Reply to author
Forward
0 new messages