AWS Content Type Settings in S3 Using Boto3

Content-Type isn't custom metadata, which is what Metadata is used for. It has its own property which can be set like this:

bucket.put_object(Key='index.html', Body=data, ContentType='text/html')

Note: .put_object() can set more than just Content-Type. Check out the Boto3 documentation for the rest.


You can also do it with the upload_file() method and ExtraArgs keyword (and set the permissions to World read as well):

import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file('source_file_name.html', 'my.bucket.com', 'aws_file_name.html', ExtraArgs={'ContentType': "application/json", 'ACL': "public-read"} )