I'm looking for a way to protect images uploaded from a Heroku Rails 3 app using the dragonfly gem to a S3 storage. I'd like to control access on a user basis and ensure that the images can't be accessed directly.
I've found some information for other gems such as paperclip, but since dragonfly works a bit differently, I'm not sure what's the preferred way to deal with this case.
Since I’m currently using a routed endpoint, expiring urls unfortunately don’t work for me.
I found, that setting an
x-amz-acl
header to set the permissions, works in my case since all images are exclusively accessed through the application and never directly.Another way to do this programmatically for some images can be achieved using calling the method
put_object_acl
directly on the Dragonfly’s Fog storage instance, e.g. in a model callback:This will of course work only if the storage in use is in fact a Fog storage, hence a check would be needed.
I don’t have any tests for this solution currently, since it seems to involve a lot of mocking. So, if anyone has some input on this solution, I would highly appreciate hearing about it!