Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/backend/app/routers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyaslreport import generate_report, get_bids_metadata
from pyaslreport.enums import ModalityTypeValues
from fastapi.responses import FileResponse
from starlette.background import BackgroundTask
from weasyprint import HTML
from app.utils.report_template import render_report_html
from app.utils.lib import default_serializer, save_upload, remove_dir
Expand Down Expand Up @@ -129,5 +130,10 @@ async def download_pdf(report_data: dict):
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
HTML(string=html_content).write_pdf(tmp.name)
tmp_path = tmp.name
return FileResponse(tmp_path, media_type="application/pdf", filename="report.pdf")
return FileResponse(
tmp_path,
media_type="application/pdf",
filename="report.pdf",
background=BackgroundTask(os.unlink, tmp_path)
)