Reputation: 4388
Currently I am using a S3 bucket to upload some pdfs.
Now none of those pdfs are directly accessible via url. But I want to make some specific pdfs public during upload.
I have gone this blog which explains how to make all the resources in a bucket public. But I do not want this, I want only few specific files to be public during upload.
Currently I am using ruby aws-sdk. I want to know is this possible?
Upvotes: 0
Views: 2109
Reputation: 5154
Since you didn't paste any specific code snippet you use, I assume you atr trying to achieve this using official AWS Ruby SDK
File.open('/source/file/path', 'rb') do |file|
s3.put_object(bucket: 'bucket-name', key: 'object-key', body: file)
end
By default, any uploaded file is private, therefore not accessible by URL.
If you want to make it public, additional param needs to be set: acl: "public-read"
. By default, all AWS SDKs are using ACL private
. So modifying my last example, it will look like:
File.open('/source/file/path', 'rb') do |file|
s3.put_object(acl: "public-read", bucket: 'bucket-name', key: 'object-key', body: file)
end
Now you should be able to access your file by URL.
You can read more about canned ACLs on S3 here: http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Upvotes: 1