Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in AWS by (19.1k points)

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?

1 Answer

0 votes
by (44.4k points)

The following snippet will update the ACL for all objects in your bucket so anyone can read them.

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

You can set the ACL for an object you are uploading.

# 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://..."

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...