It's for app engine's blobstore since its upload interface generates a temporary endpoint every time. I'd like to take the comlexity out of frontend, Flask would take the post request and forward it to the end point specified by blobstore. Performance and traffic cost is not a concern at all, can someone recommend a most straightforward way to implement?
Looking at the docs for the BlobStore flow it looks like all you need to do is accept the file yourself and then send it on to the endpoint specified by 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With