From 6f31e2d1bf23013536e9bc5a29920029136efcca Mon Sep 17 00:00:00 2001 From: emergent-agent-e1 Date: Tue, 31 Mar 2026 17:06:08 +0000 Subject: [PATCH] auto-commit for f98ebdaa-fbba-4c66-9771-4cbcbad2b530 --- backend/routes/other_routes.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/routes/other_routes.py b/backend/routes/other_routes.py index 838e255..df67559 100644 --- a/backend/routes/other_routes.py +++ b/backend/routes/other_routes.py @@ -3,6 +3,7 @@ from fastapi.responses import FileResponse from typing import List from models.schemas import ContactCreate, NewsletterSubscribe from datetime import datetime +from pathlib import Path import uuid import os import shutil @@ -12,6 +13,10 @@ router = APIRouter(prefix="/api", tags=["Other"]) # MongoDB connection will be injected db = None +# Upload directory setup +UPLOAD_DIR = Path(__file__).parent.parent / 'uploads' +UPLOAD_DIR.mkdir(exist_ok=True) + def set_db(database): global db db = database @@ -55,7 +60,7 @@ async def upload_image(file: UploadFile = File(...)): # Generate unique filename unique_filename = f"{uuid.uuid4()}{file_ext}" - file_path = f"/app/backend/uploads/{unique_filename}" + file_path = UPLOAD_DIR / unique_filename # Save file with open(file_path, "wb") as buffer: @@ -69,9 +74,9 @@ async def upload_image(file: UploadFile = File(...)): @router.get("/uploads/{filename}") async def get_uploaded_image(filename: str): """Serve uploaded images""" - file_path = f"/app/backend/uploads/{filename}" + file_path = UPLOAD_DIR / filename - if not os.path.exists(file_path): + if not file_path.exists(): raise HTTPException(status_code=404, detail="Image not found") - return FileResponse(file_path) + return FileResponse(str(file_path))