From 223e3e60ff6337fc496e67a325da23f97970d3d9 Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 12 Dec 2024 15:26:12 +0100 Subject: [PATCH] Delete PDF after OCR --- src/app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app.py b/src/app.py index 6eea5e7..109c7da 100755 --- a/src/app.py +++ b/src/app.py @@ -11,6 +11,7 @@ import sentry_sdk from starlette.concurrency import run_in_threadpool from starlette.responses import PlainTextResponse, FileResponse +from starlette.background import BackgroundTask from catch_exceptions import catch_exceptions from configuration import MONGO_HOST, MONGO_PORT, service_logger, OCR_OUTPUT, DOCUMENT_LAYOUT_ANALYSIS_URL @@ -97,8 +98,8 @@ async def upload_pdf(namespace, file: UploadFile = File(...)): @app.get("/processed_pdf/{namespace}/{pdf_file_name}", response_class=FileResponse) async def processed_pdf(namespace: str, pdf_file_name: str): + path = join(OCR_OUTPUT, namespace, pdf_file_name) + return FileResponse( - path=join(OCR_OUTPUT, namespace, pdf_file_name), - media_type="application/pdf", - filename=pdf_file_name, + path=path, media_type="application/pdf", filename=pdf_file_name, background=BackgroundTask(os.remove, path) )