我正在使用flask通过ajax上传文件,代码是:
app = Flask(name)
app.config["TEMPLATES_AUTO_RELOAD"] = True
CORS(app)
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
@app.route("/upload//<element_id>", methods=['GET', 'POST'])
def ws_product_upload(element_id):
print("Starting....")
if request.is_xhr:
print("xhr request received")
if request.method == 'POST':
f = request.files['file']
process_inmemory( element_id, file=f)
print("file received by post")
if request.is_xhr:
print("xhr request received inside post")
return json.dumps({'result': True})
return json.dumps({'result': True})
return 'file uploaded needs a post call'
当我发送图像时,一切正常,但使用简单的 txt 文件时,会失败。
我努力了:
app.config["UPLOADED_FILES_ALLOW"] = ['.txt'] # with [] and with out with . and without and nothin
app.config["UPLOADED_FILES_DENY"] = 'exe'
我想用几乎所有的 mime 类型和扩展来做到这一点
我正在使用nginx + Gunicorn(不知道是否相关)
女巫才是正确的做法
神不在的星期二
子衿沉夜
相关分类