Здесь file_name = 'imgs_ / 1_image004.jpg'.
Когда я пытаюсь вызвать эту функцию, она показывает мне ошибку в строке
bucket.put_object(Key=file_name, Body=f_content, ACL='public-read')
и ошибка выглядит как
ClientError: Произошла ошибка (AccessDenied) при вызове
Операция PutObject: доступ запрещен.
И мой код:
def upload_image_to_s3(file_name, f_content):
import ipdb;
ipdb.set_trace();
#
s3 = boto3.resource('s3', aws_access_key_id=conf.AWS_ACCESS_KEY,
aws_secret_access_key=conf.AWS_SECRET_ACCESS_KEY,
region_name=conf.REGION)
#
#
BUCKET_NAME = conf.BUCKET_NAME
PATH = conf.IMAGE_UPLOAD_PATH
REGION = conf.REGION
bucket = s3.Bucket(BUCKET_NAME)
exists = True
try:
s3.meta.client.head_bucket(Bucket=BUCKET_NAME)
except botocore.exceptions.ClientError as e:
# If a client error is thrown, then check that it was a 404 error.
# If it was a 404 error, then the bucket does not exist.
error_code = int(e.response['Error']['Code'])
if error_code == 404:
exists = False
bucket.put_object(Key=file_name, Body=f_content, ACL='public-read')
s3_path = "https://" + REGION + ".amazonaws.com/" + BUCKET_NAME + "/" + PATH + "/" + file_name
return s3_path