Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import io
- AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
- AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
- S3_BUCKET_NAME = "S3_BUCKET_NAME"
- s3 = boto3.client("s3")
- bucket_name = S3_BUCKET_NAME
- s3 = boto3.client(
- "s3",
- aws_access_key_id=AWS_ACCESS_KEY_ID,
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
- )
- def upload_base64_image_list_to_s3(base64_image_list):
- urls_list = []
- for i, base64_image in enumerate(base64_image_list):
- image_bytes = base64.b64decode(base64_image)
- image = Image.open(io.BytesIO(image_bytes))
- file_name = f"{uuid.uuid4()}.png"
- image.save(file_name)
- s3.upload_file(file_name, bucket_name, file_name)
- os.remove(file_name)
- file_url = f"https://{bucket_name}.s3.amazonaws.com/{file_name}"
- urls_list.append(file_url)
- return urls_list
Add Comment
Please, Sign In to add comment