gpt4 book ai didi

python - 使用 Flask 作为通过代理进行文件上传?

转载 作者:行者123 更新时间:2023-11-28 16:37:05 24 4
gpt4 key购买 nike

它适用于 App Engine 的 blobstore,因为它的上传接口(interface)每次都会生成一个临时端点。我想消除前端的复杂性,Flask 会接受发布请求并将其转发到 blobstore 指定的端点。性能和流量成本根本不是问题,有人可以推荐一种最直接的实现方式吗?

最佳答案

查看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"

关于python - 使用 Flask 作为通过代理进行文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com