Merge pull request #1881 from siiddhantt/fix/glacier-images

fix: s3 storage class for image upload
This commit is contained in:
Alex
2025-07-10 12:00:55 +01:00
committed by GitHub
3 changed files with 13 additions and 4 deletions

View File

@@ -168,7 +168,7 @@ def handle_image_upload(
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
upload_path = f"{settings.UPLOAD_FOLDER.rstrip('/')}/{user}/{base_path.rstrip('/')}/{uuid.uuid4()}_{filename}" upload_path = f"{settings.UPLOAD_FOLDER.rstrip('/')}/{user}/{base_path.rstrip('/')}/{uuid.uuid4()}_{filename}"
try: try:
storage.save_file(file, upload_path) storage.save_file(file, upload_path, storage_class="STANDARD")
image_url = upload_path image_url = upload_path
except Exception as e: except Exception as e:
current_app.logger.error(f"Error uploading image: {e}") current_app.logger.error(f"Error uploading image: {e}")

View File

@@ -1,4 +1,5 @@
"""Base storage class for file system abstraction.""" """Base storage class for file system abstraction."""
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import BinaryIO, List, Callable from typing import BinaryIO, List, Callable
@@ -7,7 +8,7 @@ class BaseStorage(ABC):
"""Abstract base class for storage implementations.""" """Abstract base class for storage implementations."""
@abstractmethod @abstractmethod
def save_file(self, file_data: BinaryIO, path: str) -> dict: def save_file(self, file_data: BinaryIO, path: str, **kwargs) -> dict:
""" """
Save a file to storage. Save a file to storage.

View File

@@ -38,9 +38,17 @@ class S3Storage(BaseStorage):
region_name=region_name, region_name=region_name,
) )
def save_file(self, file_data: BinaryIO, path: str) -> dict: def save_file(
self,
file_data: BinaryIO,
path: str,
storage_class: str = "INTELLIGENT_TIERING",
**kwargs,
) -> dict:
"""Save a file to S3 storage.""" """Save a file to S3 storage."""
self.s3.upload_fileobj(file_data, self.bucket_name, path) self.s3.upload_fileobj(
file_data, self.bucket_name, path, ExtraArgs={"StorageClass": storage_class}
)
region = getattr(settings, "SAGEMAKER_REGION", None) region = getattr(settings, "SAGEMAKER_REGION", None)