Make a bucket public in Amazon S3

You can set a bucket policy as detailed in this blog post: http://ariejan.net/2010/12/24/public-readable-amazon-s3-bucket-policy/ As per @robbyt’s suggestion, create a bucket policy with the following JSON: { “Version”: “2008-10-17”, “Statement”: [ { “Sid”: “AllowPublicRead”, “Effect”: “Allow”, “Principal”: { “AWS”: “*” }, “Action”: [ “s3:GetObject” ], “Resource”: [ “arn:aws:s3:::bucket/*” ] } ] } Important: replace bucket in … Read more

How to write a file or data to an S3 object using boto3

In boto 3, the ‘Key.set_contents_from_’ methods were replaced by Object.put() Client.put_object() For example: import boto3 some_binary_data = b’Here we have some data’ more_binary_data = b’Here we have some more data’ # Method 1: Object.put() s3 = boto3.resource(‘s3’) object = s3.Object(‘my_bucket_name’, ‘my/key/including/filename.txt’) object.put(Body=some_binary_data) # Method 2: Client.put_object() client = boto3.client(‘s3′) client.put_object(Body=more_binary_data, Bucket=”my_bucket_name”, Key=’my/key/including/anotherfilename.txt’) Alternatively, the binary … Read more

Amazon S3 direct file upload from client browser – private key disclosure

I think what you want is Browser-Based Uploads Using POST. Basically, you do need server-side code, but all it does is generate signed policies. Once the client-side code has the signed policy, it can upload using POST directly to S3 without the data going through your server. Here’s the official doc links: Diagram: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingHTTPPOST.html Example … Read more

how to upload multiple images to a blog post in django

You’ll just need two models. One for the Post and the other would be for the Images. Your image model would have a foreignkey to the Post model: from django.db import models from django.contrib.auth.models import User from django.template.defaultfilters import slugify class Post(models.Model): user = models.ForeignKey(User) title = models.CharField(max_length=128) body = models.CharField(max_length=400) def get_image_filename(instance, filename): title … Read more