文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 7d061cfa by 李景熙

修改中文命名文件无法上传的bug

parent a4d383a2
...@@ -27,8 +27,7 @@ def upload(): ...@@ -27,8 +27,7 @@ def upload():
os.makedirs(file_dir) os.makedirs(file_dir)
f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值 f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值
if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型
fName = secure_filename(f.filename) ext = os.path.splitext(f.filename)[1]# 获取文件后缀
ext = os.path.splitext(fName)[1]# 获取文件后缀
unix_time = int(time.time()) unix_time = int(time.time())
new_filename = str(unix_time)+ext # 修改了上传的文件名 new_filename = str(unix_time)+ext # 修改了上传的文件名
f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录 f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
...@@ -46,7 +45,7 @@ def download(fileName): ...@@ -46,7 +45,7 @@ def download(fileName):
@uploadDownload.route('/delFile', methods=['POST']) @uploadDownload.route('/delFile', methods=['POST'])
def delFile(): def delFile():
data = request.get_json(silent=True) data = request.get_json(silent=True)
url = data['url'] url=data['url']
file_dir = os.path.join(basedir, UPLOAD_FOLDER, url[39:]) file_dir = os.path.join(basedir, UPLOAD_FOLDER, url[39:])
if not os.path.exists(file_dir): if not os.path.exists(file_dir):
return jsonify({"code": 0, "errmsg": u"failed"}) return jsonify({"code": 0, "errmsg": u"failed"})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment