Spaces:
Sleeping
Sleeping
File size: 2,705 Bytes
1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 3b7f661 1235a65 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # made for adding s3 storage, no longer in need due to reach storage
# import uuid
# from io import BytesIO
# import boto3
# from botocore.exceptions import ClientError
# from app.config.settings import settings
# def get_s3_client():
# return boto3.client(
# "s3",
# aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
# aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
# region_name=settings.AWS_REGION,
# )
# def upload_image_to_s3(image_data, brand_name, image_format, index):
# try:
# s3_client = get_s3_client()
# unique_id = str(uuid.uuid4())[:8]
# filename = f"{brand_name.replace(' ', '_')}_{index}_{unique_id}.{image_format}"
# s3_client.upload_fileobj(
# BytesIO(image_data),
# settings.S3_BUCKET_NAME,
# filename,
# ExtraArgs={"ContentType": f"image/{image_format}"},
# )
# url = f"https://{settings.S3_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/{filename}"
# return {
# "id": f"logo_{index}",
# "url": url,
# "format": image_format,
# "name": filename,
# }
# except ClientError as e:
# raise Exception(f"S3 upload error: {str(e)}")
# def upload_logo_to_s3(image_data: bytes, brand_name: str, image_format: str, index: int):
# try:
# s3_client = get_s3_client()
# unique_id = str(uuid.uuid4())[:8]
# filename = f"{brand_name.replace(' ', '')}{index}_{unique_id}.{image_format.lower()}"
# if image_format.lower() == "svg":
# extra_args = {
# "ContentType": "image/svg+xml",
# "ContentDisposition": "inline",
# }
# elif image_format.lower() == "ico":
# extra_args = {
# "ContentType": "image/x-icon",
# "ContentDisposition": "inline",
# }
# else:
# extra_args = {
# "ContentType": f"image/{image_format.lower()}",
# }
# s3_client.upload_fileobj(
# BytesIO(image_data),
# settings.S3_BUCKET_NAME,
# filename,
# ExtraArgs=extra_args,
# )
# url = f"https://{settings.S3_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/{filename}"
# return {
# "id": f"logo_{index}",
# "url": url,
# "format": image_format,
# "name": filename,
# }
# except ClientError as e:
# raise Exception(f"S3 upload error: {str(e)}") |