Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am trying to upload a web page to an S3 bucket using Amazon's Boto3 SDK for Python.

I am having trouble setting the Content-Type. AWS keeps creating a new metadata key for Content-Type in addition to the one I'm specifying using this code:

# Upload a new file

data = open('index.html', 'rb')

x = s3.Bucket('website.com').put_object(Key='index.html', Body=data)

x.put(Metadata={'Content-Type': 'text/html'})

Any guidance of how to set Content-Type to text/html would be greatly appreciated.

1 Answer

0 votes
by (119k points)
edited by

Content-Type is not custom metadata and metadata is used for that.  It has its own property which can be set like this:bucket.put_object(Key='index.html', Body=data, ContentType='text/html')

If you want to learn more, check out this AWS Training Course by Intellipaat.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...