Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby aws-sdk - grant permission to all users

I am writing the code to grant READ permissions to all users using aws-sdk gem. In the documentation for the gem, I found the following:

bucket.objects.each do |object|
  puts object.key
  acl = object.acl
  acl.grant(:read).to("TODO: how can I specify 'ALL'???")
  object.acl = acl.to_xml
end

It all makes sense, however I'm not quite sure how can I tell the grant read permission to ALL users?

like image 918
alexs333 Avatar asked Oct 16 '12 07:10

alexs333


1 Answers

The example you have can work, but is more suited for complicated ACLs (access control lists). Amazon S3 has a number of canned-acls you can use for your objects. The follow snippet will update the ACL for all objects in your bucket so anyone can read them.

bucket.objects.each{|obj| obj.acl = :public_read }

Alternatively, you can set the ACL for an object when you upload (or copy) it.

# upload a file and set the acl so the world can download it
obj = bucket.objects['object-key'].write(file, :acl => :public_read)

puts obj.public_url
#=> 'https://..."
like image 125
Trevor Rowe Avatar answered Oct 24 '22 10:10

Trevor Rowe