fix: 修复下载API,添加调试日志

问题:下载API返回 "Not Found"

修复:
- 使用绝对路径:os.path.join(os.path.dirname(os.path.abspath(__file__)), 'public', 'reports')
- 添加详细调试日志:显示文件目录、文件名、文件是否存在、目录中的文件列表

请重启服务并测试下载。

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 14:20:24 +08:00
parent 5e8e69cadf
commit b51afb3b67
2 changed files with 15 additions and 1 deletions

16
app.py
View File

@@ -395,6 +395,8 @@ def download_file():
"""下载文件"""
try:
file_path = request.args.get('path')
print(f"[下载] 请求路径: {file_path}")
if not file_path:
return jsonify({'success': False, 'message': '文件路径不能为空'}), 400
@@ -403,10 +405,22 @@ def download_file():
return jsonify({'success': False, 'message': '无效的文件路径'}), 400
filename = file_path.replace('/reports/', '')
reports_dir = os.path.join('public', 'reports')
# 使用绝对路径
reports_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'public', 'reports')
print(f"[下载] 文件目录: {reports_dir}")
print(f"[下载] 文件名: {filename}")
print(f"[下载] 文件是否存在: {os.path.exists(os.path.join(reports_dir, filename))}")
# 列出目录中的所有文件
if os.path.exists(reports_dir):
print(f"[下载] 目录中的文件: {os.listdir(reports_dir)}")
return send_from_directory(reports_dir, filename, as_attachment=True)
except Exception as e:
print(f"[下载] 错误: {str(e)}")
import traceback
traceback.print_exc()
return jsonify({'success': False, 'message': str(e)}), 500

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB