David542
David542

Reputation: 110482

Automatically set boto content type

I have the following upload code:

key.set_contents_from_filename(content)
key.set_acl(acl)

I don't know what type of file I'm receiving here, but is there a way to automatically set the content type?

Upvotes: 1

Views: 305

Answers (1)

garnaat
garnaat

Reputation: 45906

The boto library automatically tries to guess the mime type using the Python mimetypes.guess_type function but this depends mostly on guessing it from the file name. If you want to explicitly provide a mime type, you can do that by setting the content_type attribute before uploading the file:

key.content_type = 'text/html'
key.set_contents_from_filename(content)

Does that answer your question?

Upvotes: 1

Related Questions