This commit is contained in:
Timothy Jaeryang Baek
2026-04-12 12:36:21 -05:00
parent a2a9a3a42a
commit 15f9a8f3f1
3 changed files with 14 additions and 14 deletions
+6 -6
View File
@@ -61,7 +61,7 @@ class LocalStorageProvider(StorageProvider):
contents = file.read()
if not contents:
raise ValueError(ERROR_MESSAGES.EMPTY_CONTENT)
file_path = f'{UPLOAD_DIR}/{filename}'
file_path = os.path.join(UPLOAD_DIR, filename)
with open(file_path, 'wb') as f:
f.write(contents)
return contents, file_path
@@ -74,8 +74,8 @@ class LocalStorageProvider(StorageProvider):
@staticmethod
def delete_file(file_path: str) -> None:
"""Handles deletion of the file from local storage."""
filename = file_path.split('/')[-1]
file_path = f'{UPLOAD_DIR}/{filename}'
filename = os.path.basename(file_path)
file_path = os.path.join(UPLOAD_DIR, filename)
if os.path.isfile(file_path):
os.remove(file_path)
else:
@@ -202,7 +202,7 @@ class S3StorageProvider(StorageProvider):
return '/'.join(full_file_path.split('//')[1].split('/')[1:])
def _get_local_file_path(self, s3_key: str) -> str:
return f'{UPLOAD_DIR}/{s3_key.split("/")[-1]}'
return os.path.join(UPLOAD_DIR, s3_key.split('/')[-1])
class GCSStorageProvider(StorageProvider):
@@ -234,7 +234,7 @@ class GCSStorageProvider(StorageProvider):
"""Handles downloading of the file from GCS storage."""
try:
filename = file_path.removeprefix('gs://').split('/')[1]
local_file_path = f'{UPLOAD_DIR}/{filename}'
local_file_path = os.path.join(UPLOAD_DIR, filename)
blob = self.bucket.get_blob(filename)
blob.download_to_filename(local_file_path)
@@ -298,7 +298,7 @@ class AzureStorageProvider(StorageProvider):
"""Handles downloading of the file from Azure Blob Storage."""
try:
filename = file_path.split('/')[-1]
local_file_path = f'{UPLOAD_DIR}/{filename}'
local_file_path = os.path.join(UPLOAD_DIR, filename)
blob_client = self.container_client.get_blob_client(filename)
with open(local_file_path, 'wb') as download_file:
download_file.write(blob_client.download_blob().readall())