Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading images to s3 with meta = image/jpeg - python/boto3

How do I go about setting ContentType on images that I upload to AWS S3 using boto3 to content-type:image/jpeg?

Currently, I upload images to S3 using buto3/python 2.7 using the following command:

s3.upload_fileobj(bytes_io_file, bucket_name, filename)

However, to set the uploaded object's type to ContentType= 'image/jpeg', I have to manually select all 'folders' on S3 through the web interface, and set metadata to Content-type : Image/jpeg

Is there a way to set this flag in the upload request i have above?

Thank you in advance!

like image 281
FlyingZebra1 Avatar asked Jan 03 '23 14:01

FlyingZebra1


1 Answers

Add it in the ExtraArgs argument:

s3.upload_fileobj(bytes_io_file, bucket_name, filename, ExtraArgs={ "ContentType": "image/jpeg"})
like image 53
Ollie Avatar answered Jan 05 '23 17:01

Ollie