Python - Make S3 images public as they are uploaded?
<p>I'm using this code to upload images to S3 from python but I need them to be public right away instead of changing permissions manually.</p>

<pre><code>im2.save(out_im2, 'PNG')
conn = boto.connect_s3(keys)

b = conn.get_bucket('example')
k = b.new_key('example.png')
k.set_contents_from_string(out_im2.getvalue())
</code></pre>

<p>I already tried this code:</p>

<pre><code>b.set_acl('public-read-write')
</code></pre>

<h2>Using ACLs</h2>

<p>Try:</p>

<pre><code>k.set_acl('public-read')
</code></pre>

<p>According to <a href="http://boto.cloudhackers.com/en/latest/s3_tut.html#setting-getting-the-access-control-list-for-buckets-and-keys" rel="nofollow">the boto documentation</a> this is how you set a canned ACL on an individual item.</p>

<p>Change the acl on the bucket (as you were doing with <code>b.set_acl</code>, will only affecting permissions on bucket operations (such as List Objects in a Bucket), not object operations, such as reading an object (which is what you want).  See <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#permissions" rel="nofollow">Amazon S3 ACL Overview - Permissions</a> for more details on what the different permissions mean when applied to buckets and objects.</p>

<h2>Using Bucket Policies</h2>

<p>However, depending on the key structure for your images, you may find it simpler to setup a bucket policy that grants read access to all keys in a given path.  Then you don't have to do anything special with any individual objects.</p>

<p><a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html#example-bucket-policies-use-case-2" rel="nofollow">Here is a sample policy that grants read-only access</a>.</p>

<p>And <a href="https://blogs.aws.amazon.com/security/post/TxPOJBY6FE360K/IAM-policies-and-Bucket-Policies-and-ACLs-Oh-My-Controlling-Access-to-S3-Resourc" rel="nofollow">this blog post discusses the differences and combinations between IAM Policies, Bucket Policies and ACLs</a>.</p>

python amazon-web-services amazon-s3 boto