>我必须通过curl命令将文件上传到烧瓶。我尝试使用 Flask 上传文件夹/文件中的 curl 命令发送,但它无法识别请求。
curl --form "fileupload=@filename.txt" http://hostname/resource
还有 Python 代码:
from flask import Flask,abort,render_template,request,redirect,url_for
from werkzeug import secure_filename
import os
app = Flask(__name__)
UPLOAD_FOLDER = './uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/upload/',methods = ['POST'])
def upload_file():
if request.method =='POST':
file = request.files['file']
print request.files
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
if __name__ == '__main__':
app.run(debug = True)
数据应在通过 CURL 命令发布时保存
好吧,您可能需要返回一些东西,没有它 烧瓶给你错误 尝试添加
return jsonify({'message':'File uploaded!'})
之后,尝试一下:)记得从烧瓶导入jsonify!