Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add metadata to image upload to S3 with Python

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'.

like image 471
captDaylight Avatar asked Feb 09 '12 21:02

captDaylight


1 Answers

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.

like image 160
tkone Avatar answered Sep 22 '22 06:09

tkone