From 2891b335b0ad02510a8d4d881daa599847fcaf18 Mon Sep 17 00:00:00 2001 From: Christian Krakau-Louis Date: Mon, 24 Mar 2025 17:02:56 +0100 Subject: [PATCH] added ui upload route --- app/main.py | 19 ++++++++++++++++++- app/routes_ui.py | 26 -------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 app/routes_ui.py diff --git a/app/main.py b/app/main.py index 9739c1f5..c26207ec 100644 --- a/app/main.py +++ b/app/main.py @@ -113,4 +113,21 @@ def process_all_pdfs_in_workdir(): "task_ids": task_ids } -app.include_router(frontend_router) \ No newline at end of file +app.include_router(frontend_router) + +@router.post("/ui-upload") +async def ui_upload(file: UploadFile = File(...)): + # You can store this file in your 'workdir' (like how /process does) or a tmp dir + workdir = "/workdir" + target_path = os.path.join(workdir, file.filename) + + try: + with open(target_path, "wb") as f: + content = await file.read() + f.write(content) + except Exception as e: + raise HTTPException(status_code=500, detail=f"Failed to save file: {e}") + + # Now you can call your existing Celery flow: + task = upload_to_s3.delay(target_path) + return {"task_id": task.id, "status": "queued"} \ No newline at end of file diff --git a/app/routes_ui.py b/app/routes_ui.py deleted file mode 100644 index 2ddd949d..00000000 --- a/app/routes_ui.py +++ /dev/null @@ -1,26 +0,0 @@ -# In main.py or a new dedicated file, e.g. app/routes_ui.py -from fastapi import APIRouter, UploadFile, File, HTTPException -from app.tasks.upload_to_s3 import upload_to_s3 -import os - -router = APIRouter() - -@router.post("/ui-upload") -async def ui_upload(file: UploadFile = File(...)): - # You can store this file in your 'workdir' (like how /process does) or a tmp dir - workdir = "/workdir" - target_path = os.path.join(workdir, file.filename) - - try: - with open(target_path, "wb") as f: - content = await file.read() - f.write(content) - except Exception as e: - raise HTTPException(status_code=500, detail=f"Failed to save file: {e}") - - # Now you can call your existing Celery flow: - task = upload_to_s3.delay(target_path) - return {"task_id": task.id, "status": "queued"} - -# Then include this in your main app as well: -# app.include_router(router)