【发布时间】:2017-10-08 11:09:10
【问题描述】:
如何在 Flask-RESTful PUT 处理程序方法中保存使用 curl 命令(如 curl localhost:5000/upload/test.bin --upload-file tmp/test.bin)上传的数据?
Ron Harlev's answer 到 Flask-RESTful - Upload image 中的代码适用于来自 curl -F "file=@tmp/test.bin" localhost:5000/upload/test.bin 的 POST 请求(以下稍作修改):
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)
但是,如果我尝试使用代码来处理来自curl --upload-file 的 PUT 请求(当然,将上面的post 更改为put)我会得到:“'NoneType' 对象没有属性'save'”。这指的是上面代码中的倒数第二行。
如何获取使用curl --upload-file上传的文件数据的句柄,以便将其保存到本地文件?
更新:这可以解决问题:curl --request PUT -F "file=@tmp/test.bin" localhost:5000/upload/test.bin,但我的问题仍然没有答案。
【问题讨论】:
标签: python curl flask put flask-restful