diff --git a/backend/app/api/routes/uploads.py b/backend/app/api/routes/uploads.py index 3fe43de..6ea6330 100644 --- a/backend/app/api/routes/uploads.py +++ b/backend/app/api/routes/uploads.py @@ -13,8 +13,6 @@ from app.schemas.presigned_urls import PresignedUrlResponse, PresignedUrlRequest router = APIRouter() - - @router.post("/presigned-url", response_model=PresignedUrlResponse, operation_id="generate_presigned_url") async def generate_presigned_url( request: PresignedUrlRequest, @@ -98,7 +96,7 @@ async def upload_file( await storage.save_file(file, destination) # Return the file URL - return {"file_url": storage.get_file_url(destination)} + return {"file_url": storage.get_uploaded_file_url(destination)} except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/backend/app/core/storage.py b/backend/app/core/storage.py index 97b842b..2f819ff 100644 --- a/backend/app/core/storage.py +++ b/backend/app/core/storage.py @@ -12,6 +12,7 @@ from app.core.config import settings class StorageProvider(ABC): """Base abstract class for storage providers.""" upload_folder: Path + @abstractmethod async def save_file(self, file: UploadFile, destination: str) -> str: """Save a file to storage and return the relative path.""" @@ -28,6 +29,11 @@ class StorageProvider(ABC): """ pass + @abstractmethod + def get_uploaded_file_url(self, file_path: str) -> str: + """Get the URL for accessing a file.""" + pass + @abstractmethod def get_file_url(self, file_path: str) -> str: """Get the URL for accessing a file.""" @@ -74,10 +80,14 @@ class LocalStorageProvider(StorageProvider): upload_url = f"{settings.API_VERSION_STR}/uploads/{token}" # The file URL is where the file will be accessible after upload - file_url = f"{self.files_url_path}/{file_path}" + file_url = f"{self.upload_folder}/{file_path}" return upload_url, file_url + def get_uploaded_file_url(self, file_path: str) -> str: + """Get the URL for accessing a file.""" + return f"{self.upload_folder}/{file_path}" + def get_file_url(self, file_path: str) -> str: """Get the URL for accessing a file.""" return f"{self.files_url_path}/{file_path}" diff --git a/backend/tests/core/storage.py b/backend/tests/core/storage.py index bf6053d..b1bd95d 100644 --- a/backend/tests/core/storage.py +++ b/backend/tests/core/storage.py @@ -70,6 +70,6 @@ def test_get_file_url(test_storage): """Test getting a file URL.""" file_path = "images/test.jpg" - url = test_storage.get_file_url(file_path) + url = test_storage.get_uploaded_file_url(file_path) assert url == f"/test-files/{file_path}"