它适用于app引擎的blobstore,因为它的上传界面每次都会生成一个临时端点。我想从前端获取复杂性,Flask会接受post请求并将其转发到blobstore指定的端点。性能和流量成本根本不是问题,有人可以推荐一种最直接的方式来实现吗?
答案 0 :(得分:3)
查看the docs for the BlobStore flow看起来您需要做的就是自己接受该文件,然后将其发送到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"