Python AWS boto3-如何显示图像而不是强制下载
我正试图上传图像到S3并显示它,但不知道如何防止强制下载 这是我为图像上传编写的函数:Python AWS boto3-如何显示图像而不是强制下载,python,amazon-web-services,amazon-s3,boto3,Python,Amazon Web Services,Amazon S3,Boto3,我正试图上传图像到S3并显示它,但不知道如何防止强制下载 这是我为图像上传编写的函数: def upload_to_aws(local_file, bucket, s3_file): s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY) try: s3.upload_file(local_file,
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
try:
s3.upload_file(local_file, bucket, s3_file, {'ACL': 'public-read', 'ContentType': 'image/jpeg'})
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
有人知道显示上传图像的正确配置吗?看起来您错过了
ExtraArgs
属性。
请看以下代码段:
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file(local_file, bucket, s3_file, ExtraArgs={'ACL': 'public-read', 'ContentType': 'image/jpeg'})
更多关于
为了确保内容类型设置正确,您可以从S3控制台检查它,右键单击对象并选择Properties=>ChangeMetadata
尝试在
{'ACL:…