修复上传头像时格式错误的问题
This commit is contained in:
parent
c9efcd3571
commit
402a83e651
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user