Spaces:
Paused
Paused
| import boto3, os | |
| from dotenv import load_dotenv | |
| s3 = boto3.client( | |
| "s3", | |
| aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"), | |
| aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"), | |
| region_name=os.getenv("AWS_REGION"), | |
| ) | |
| bucket = os.getenv("S3_BUCKET") | |
| def upload_to_s3(file, key): | |
| s3.upload_fileobj(file.file, bucket, key) | |
| return f"https://{bucket}.s3.amazonaws.com/{key}" | |
| def upload_pdf_bytes(data: bytes, key: str): | |
| s3.put_object(Bucket=bucket, Key=key, Body=data, ContentType="application/pdf") | |
| return f"https://{bucket}.s3.amazonaws.com/{key}" | |