Spaces:
Sleeping
Sleeping
Upload s3_utils.py
Browse files41 unmodified lines42434441 unmodified lines}except ClientError as e:raise Exception(f"S3 upload error: {str(e)}")41 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858641 unmodified lines}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):"""Uploads an image (PNG, JPG, or SVG) to S3 with proper headers.SVGs get ContentType 'image/svg+xml' and ContentDisposition 'inline'.Does NOT set ACL because bucket disallows ACLs."""try:s3_client = get_s3_client()unique_id = str(uuid.uuid4())[:8]filename = f"{brand_name.replace(' ', '')}{index}_{unique_id}.{image_format}"# Set headers depending on image formatif image_format.lower() == "svg":extra_args = {"ContentType": "image/svg+xml","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)}")
app/utils/s3_utils.py+42