FlyingZebra1
FlyingZebra1

Reputation: 1346

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!

Upvotes: 6

Views: 5736

Answers (1)

Ollie
Ollie

Reputation: 1702

Add it in the ExtraArgs argument:

s3.upload_fileobj(bytes_io_file, bucket_name, filename, ExtraArgs={ "ContentType": "image/jpeg"})

Upvotes: 12

Related Questions