Python 如何在Flask RESTful中解析curl-PUT请求?

Python 如何在Flask RESTful中解析curl-PUT请求?,python,curl,flask,put,flask-restful,Python,Curl,Flask,Put,Flask Restful,如何使用curl命令(如curl localhost:5000/upload/test.bin--upload file tmp/test.bin)将上传的数据保存在Flask RESTful PUT处理程序方法中 to中的代码与来自curl-F“file=@tmp/test.bin”localhost:5000/upload/test.bin的POST请求一起工作(下面稍作修改): 但是,如果我尝试使用代码来处理来自curl--upload file(当然,将上面的post更改为PUT),我会

如何使用curl命令(如
curl localhost:5000/upload/test.bin--upload file tmp/test.bin
)将上传的数据保存在Flask RESTful PUT处理程序方法中

to中的代码与来自
curl-F“file=@tmp/test.bin”localhost:5000/upload/test.bin的POST请求一起工作(下面稍作修改):

但是,如果我尝试使用代码来处理来自
curl--upload file
(当然,将上面的
post
更改为
PUT
),我会得到:“'NoneType'对象没有属性‘save'”。这是指上述代码中的最后第二行

如何获得使用
curl--upload file
上传的文件数据的句柄,以便将其保存到本地文件

更新:这解决了这个问题:
curl--request PUT-F“file=@tmp/test.bin”localhost:5000/upload/test.bin
,但我仍然没有回答我的问题。

curls文档将--upload file定义为PUT http请求

我不确定是否需要通过restful API来处理这个问题,我很确定这就是curl造成问题的原因,也许必须通过restful来处理这个问题的假设会阻碍您

也许可以尝试将其构建为一个端点,但这段代码应该适合您

从烧瓶导入烧瓶,请求,jsonify
...
@app.route('/simpleupload/',方法=['POST','PUT'])
def flask_上载(文件路径):
以open(“/tmp/{}.format(filepath),“wb”)作为文件:
file.write(request.stream.read())
返回(jsonify({'filepath':filepath}),200)
curls文档定义--将文件上载为PUT http请求

我不确定是否需要通过restful API来处理这个问题,我很确定这就是curl造成问题的原因,也许必须通过restful来处理这个问题的假设会阻碍您

也许可以尝试将其构建为一个端点,但这段代码应该适合您

从烧瓶导入烧瓶,请求,jsonify
...
@app.route('/simpleupload/',方法=['POST','PUT'])
def flask_上载(文件路径):
以open(“/tmp/{}.format(filepath),“wb”)作为文件:
file.write(request.stream.read())
返回(jsonify({'filepath':filepath}),200)
def post(self, filepath):
    parse = reqparse.RequestParser()
    parse.add_argument('file', type=werkzeug.datastructures.FileStorage, location='files')
    args = parse.parse_args()
    upload_file = args['file']
    upload_file.save("/usr/tmp/{}".format(filepath))
    return ({'filepath': filepath}, 200)