使用python上传s3图像的元数据



我正在使用python boto3上传图像到s3。无法将s3对象的元数据字段设置为"image/png"。代码:

s3.put_object(Bucket=settings.AWS_STORAGE_PRIVATE_BUCKET_NAME,
Key=s3_storage_path,
Body=file_content,
Metadata={"Content-Type":"image/png"},
)

元数据被系统设置为"binary/octet-stream&;

使用put_object时,内容类型通过ContentType参数设置,不能通过Metadata参数设置。

ContentType (string)——描述内容格式的标准MIME类型。欲了解更多信息,请参见http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17。

试题:

s3.put_object(
Bucket=settings.AWS_STORAGE_PRIVATE_BUCKET_NAME,
Key=s3_storage_path,
Body=file_content,
ContentType='image/png'
)