I'm successfully adding an image to a bucket on S3, but the problem is I'm not sure how to set the content-type to 'image/png'. Here is my code
image = Image.open(self.image)
conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
out_im2 = cStringIO.StringIO()
image.save(out_im2, 'PNG')
b = conn.get_bucket('new_test_bucket')
k = b.new_key(self.title+'.png')
k.set_contents_from_filename(str(self.image))
Currently it is being uploaded as 'application/octet-stream'.
This is how my image upload code (using boto) works:
k.set_metadata('Content-Type', mime)
k.set_contents_from_file(data, policy='public-read')
k.set_acl('public-read')
Well at least part of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With