它用于应用程序引擎的 blobstore,因为它的上传接口每次都会生成一个临时端点。我想消除前端的复杂性,Flask 会接受 post 请求并将其转发到 blobstore 指定的端点。性能和流量成本根本不是问题,有人可以推荐一种最直接的实施方法吗?
看着BlobStore 流程的文档 https://developers.google.com/appengine/docs/python/blobstore/#1_create_an_upload_url看起来您需要做的就是自己接受文件,然后将其发送到指定的端点create_upload_url
:
@app.route("/upload-complete", methods=["POST"])
def handle_upload_response():
"""This will be called after every upload, but we can ignore it"""
return "Success"
@app.route("/upload", methods=["POST"])
def upload():
fp = request.files["name_of_file"]
url = create_upload_url(url_for('handle_upload_response'))
response = requests.post(url, {'file':
(fp.filename, fp.stream,
fp.content_type, fp.headers)})
if response == "Success":
return "File uploaded successfully"
else:
return "Something didn't work out"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)