How to set the content type in a file in a S3-enabled web hosting account through the Python boto module?
I do:
from boto.s3.connection import S3Connection from boto.s3.key import Key from boto.cloudfront import CloudFrontConnection conn = S3Connection(access_key_id, secret_access_key) bucket = conn.create_bucket('mybucket') b = conn.get_bucket(bucket) b.set_acl('public-read') fn = 'index.html' template = '<html>blah</html>' k = Key(b) k.key = fn k.set_contents_from_string(template) k.set_acl('public-read') k.set_metadata('Content-Type', 'text/html')
However, when I access it from http://mybucket.s3-website-us-east-1.amazonaws.com/index.html , my browser offers me to download the file instead of just serving it as a web page.
Looking at the metadata in the S3 management console, it is shown that the Content-Type was actually set to "application / octet-stream". If I manually change it in the console, I can access this page as usual, but if I run my script again, it resets it back to the wrong content type.
What am I doing wrong?
python amazon-s3 boto
Cerin
source share