使用 meta = image/jpeg - python/boto3 将图像上传到 s3 [英] Uploading images to s3 with meta = image/jpeg - python/boto3

查看:29
本文介绍了使用 meta = image/jpeg - python/boto3 将图像上传到 s3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将使用 boto3 上传到 AWS S3 的图像的 ContentType 设置为 content-type:image/jpeg?

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

目前,我使用以下命令使用 buto3/python 2.7 将图像上传到 S3:

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

s3.upload_fileobj(bytes_io_file, bucket_name, filename)

但是,要将上传对象的类型设置为 ContentType='image/jpeg',我必须通过 Web 界面手动选择 S3 上的所有文件夹",并将元数据设置为 Content-type : Image/jpeg

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?

先谢谢你!

推荐答案

将其添加到 ExtraArgs 参数中:

Add it in the ExtraArgs argument:

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

这篇关于使用 meta = image/jpeg - python/boto3 将图像上传到 s3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆