【发布时间】:2021-07-30 21:03:02
【问题描述】:
当我尝试在 python 中使用 boto3 将图像上传到 s3 时,我经常遇到错误。 错误说:
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
我上传图片的代码是
def upload_file(file_name, bucket, object_name=None):
"""Upload a file to an S3 bucket
:param file_name: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_name is used
:return: True if file was uploaded, else False
"""
# If S3 object_name was not specified, use file_name
if object_name is None:
object_name = file_name
# Upload the file
s3_client = boto3.client('s3')
try:
response = s3_client.upload_file(file_name, bucket, object_name, ExtraArgs={'ACL':'public-read'})
print(response)
except Exception as e:
print(e)
return False
return True
【问题讨论】:
标签: python amazon-web-services upload boto3 access-denied