使用 meta = image/jpeg - python/boto3 将图像上传到 s3

Fly*_*ra1 4 python amazon-s3 amazon-web-services boto3

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

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

s3.upload_fileobj(bytes_io_file, bucket_name, filename)
Run Code Online (Sandbox Code Playgroud)

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

有没有办法在我上面的上传请求中设置这个标志?

先感谢您!

Oll*_*lie 8

将其添加到ExtraArgs参数中:

s3.upload_fileobj(bytes_io_file, bucket_name, filename, ExtraArgs={ "ContentType": "image/jpeg"})
Run Code Online (Sandbox Code Playgroud)