amazon web services - Content type of S3 key is being set as 'application/octet-stream' even after explicitly setting it to "text/plain", in python boto -


i have save textfile s3 using boto. have fetched textfile using "requests" library. have written following code save file s3:

filename = "some/textfile/fi_le.txt" k = bucket.new_key(filename) k.set_contents_from_string(r.raw.read()) k.content_type = 'text/plain' print k.content_type  k = bucket.get_key(filename) print k.content_type 

the output is:

text/plain application/octet-stream 

what should set file's content_type 'text/plain'?

note: dealing lot of such files, setting manually in aws console not option.

try setting content type before call set_contents_from_string:

k = bucket.new_key(filename) k.content_type = 'text/plain' k.set_contents_from_string(r.raw.read()) 

the reason have set before, not after, because set_contents_from_string method results in file being written s3 - , once it's written, changes local object attributes won't reflected. instead, set local attributes first, before object written, they'll written when set contents.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -