From df14f81b4d34b7aea88bb5e72cbdaba70f7d728f Mon Sep 17 00:00:00 2001 From: xuyonghao <898441624@qq.com> Date: 星期三, 08 一月 2025 18:37:43 +0800 Subject: [PATCH] excel触发文件下载 --- app/api/excel.py | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/excel.py b/app/api/excel.py index 490f731..b34c183 100644 --- a/app/api/excel.py +++ b/app/api/excel.py @@ -146,14 +146,18 @@ @router.get("/download/{file_full_name}") -async def download_file(background_tasks: BackgroundTasks, file_full_name: str): +async def download_file(file_full_name: str): file_name = os.path.basename(file_full_name) user_excel = EXCEL_FILES_PATH file_path = os.path.join(user_excel, file_full_name) if not os.path.exists(file_path): return JSONResponse(content={"error": "鏂囦欢涓嶅瓨鍦�"}, status_code=404) - + return FileResponse( + path=file_path, + filename=file_name, + media_type='application/octet-stream', + ) # def delete_file(): # try: # os.unlink(file_path) -- Gitblit v1.8.0