From e95a34d49fd0e05a0823cda1e9d6b5c4cb3e6ac1 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Mon, 5 Sep 2022 21:34:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=E5=8F=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E5=90=8E=E5=B4=A9=E6=BA=83=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 40797d4..aac43f6 100644 --- a/app.py +++ b/app.py @@ -169,28 +169,31 @@ def upload_file(): return render_template('login.html') if request.method == 'POST': try: - f = request.files['file'] + file = request.files['file'] # print(f.size) # print(f) # print(request.files) - filename = secure_filename(f.filename) + filename = secure_filename(file.filename) print(f'推荐安全文件命名:{filename}') # savePath = f'js/{filename}' - savePath = f'js/{f.filename}' + savePath = f'js/{file.filename}' # print(savePath) if os.path.exists(savePath): return jsonify(error.failed(f'上传失败,文件已存在,请先查看删除再试')) with open('js/模板.js', encoding='utf-8') as f2: before = f2.read() - upcode = f.stream.read().decode('utf-8') + upcode = file.stream.read().decode('utf-8') check_to_run = before + upcode # print(check_to_run) try: js2py.eval_js(check_to_run) except: return jsonify(error.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码')) + print(savePath) + # savePath = os.path.join('', savePath) # print(savePath) - f.save(savePath) + file.seek(0) # 读取后变成空文件,重新赋能 + file.save(savePath) return jsonify(error.success('文件上传成功')) except Exception as e: return jsonify(error.failed(f'文件上传失败!{e}')) -- GitLab