简体   繁体   English

使用 http 将文件上传到运行 python flask 的服务器时,文件名中的特殊字符丢失

[英]special character in file name is missing while using http post to upload a file onto server running python flask

example file name: 2^8.txt示例文件名: 2^8.txt
my request:我的请求:

var fileSelect = document.getElementById('myfile');
var files = fileSelect.files;
var formData = new FormData();
var file = files[0]; 
formData.append('file', file, file.name);

How i printed the file name using python flask:我如何使用 python flask 打印文件名:

if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return jsonify(status="fail")
        file = request.files['file']
        filename = secure_filename(file.filename)
        print(filename)

I got 28.txt instead of 2^8.txt我得到28.txt而不是2^8.txt
I have tried using encodeURI(), but it didn't work.我曾尝试使用 encodeURI(),但它没有用。

The "^" character is being removed by the secure_filename(file.filename) function call, because werkzeug deems it unsafe (I'm not sure why but there will be a reason.). secure_filename(file.filename) function 调用正在删除“^”字符,因为 werkzeug 认为它不安全(我不知道为什么,但会有一个原因。)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM