added ui upload route

This commit is contained in:
Christian Krakau-Louis
2025-03-24 17:02:56 +01:00
parent 09db93f353
commit 2891b335b0
2 changed files with 18 additions and 27 deletions
+17
View File
@@ -114,3 +114,20 @@ def process_all_pdfs_in_workdir():
} }
app.include_router(frontend_router) 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"}
-26
View File
@@ -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)