我必须通过curl命令将文件上传到flask。我尝试使用来自Folder/Files Upload with 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命令发布时保存
答案 0 :(得分:0)
好吧,您可能需要返回一些内容,如果没有它,Flask会为您添加尝试错误提供
return jsonify({'message':'File uploaded!'})
然后尝试:)请记住从flask导入jsonify!