This commit is contained in:
Philip Cheung 2024-10-08 01:03:08 +08:00
parent 8d8af1dade
commit b1a21ffe16
1 changed files with 3 additions and 14 deletions

View File

@ -196,7 +196,7 @@ def validate_file_size_type(file: IO):
async def upload_file(file_name, bucket_name, object_name=None):
ConnectionUrl = f"https://{settings.AccountID}.r2.cloudflarestorage.com"
ConnectionUrl = f"https://{settings.AccountID}.r2.cloudflarestorage.com/images"
r2 = boto3.client(
"s3",
endpoint_url=ConnectionUrl,
@ -217,12 +217,7 @@ async def upload_file(file_name, bucket_name, object_name=None):
async def save_picture(file, folder_name: str = "", file_name: str = None):
import io
r2 = boto3.client(
"s3",
endpoint_url=f"https://{settings.AccountID}.r2.cloudflarestorage.com",
aws_access_key_id=settings.access_key_id,
aws_secret_access_key=settings.secret_access_key,
)
randon_uid = str(uuid4())
_, f_ext = os.path.splitext(file.filename)
@ -242,13 +237,7 @@ async def save_picture(file, folder_name: str = "", file_name: str = None):
# img.thumbnail(output_size)
img.save(picture_path)
ConnectionUrl = f"https://{settings.AccountID}.r2.cloudflarestorage.com/images"
S3Connect = boto3.client(
"s3",
endpoint_url=ConnectionUrl,
aws_access_key_id=settings.access_key_id,
aws_secret_access_key=settings.secret_access_key,
)
if upload_file(picture_path, "images"):
print(f"File {picture_path} uploaded successfully to images")
else: