From 402a83e651b207ab0e2027b0deaaa952eb172270 Mon Sep 17 00:00:00 2001 From: zzh Date: Fri, 21 Nov 2025 21:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=97=B6=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/app.py b/server/app.py index 6fb5342..11fd82f 100644 --- a/server/app.py +++ b/server/app.py @@ -387,11 +387,13 @@ def upload_avatar(): # 验证文件类型 allowed_extensions = {'png', 'jpg', 'jpeg', 'gif', 'webp'} - filename = secure_filename(file.filename) - if '.' not in filename: + + # 先从原始文件名获取扩展名 + original_filename = file.filename + if '.' not in original_filename: return jsonify({'error': '无效的文件格式'}), 400 - ext = filename.rsplit('.', 1)[1].lower() + ext = original_filename.rsplit('.', 1)[1].lower() if ext not in allowed_extensions: return jsonify({'error': '不支持的文件格式,请上传 PNG、JPG、GIF 或 WEBP 格式'}), 400