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.
# config/initializers/dragonfly.rb
app = Dragonfly[:images]
if Rails.env.production?
app.datastore.configure do |c|
# […]
c.storage_headers = {'x-amz-acl' => 'private'}
end
end
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:
app = Dragonfly[:images]
app.datastore.storage.put_object_acl 'bucket-name', model.image_uid, 'private'
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!