Skip to content

Commit

Permalink
Delete PDF after OCR
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-piles committed Dec 12, 2024
1 parent 99f8de3 commit 223e3e6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)

0 comments on commit 223e3e6

Please sign in to comment.