vendredi 20 décembre 2019

Flask: How to return result file of long-running task?

I'm using Flask and a HTML web form to have a user upload a file, do some processing (while the request is pending) and return the result.

@app.route('/process', methods=["POST"])
def process(
    if request.method == 'POST':

      input_file = request.files['file']

      # processing ...

      response = make_response(result_as_csv)
      response.headers["Content-Disposition"] = "attachment; filename=result.csv"
      response.headers["Content-Type"] = "text/csv"
      return response

Now, for long-running tasks, I'm running into timeouts. I'd like to have Flask return the request with 200, do the processing and then either

  • automatically open a Download file dialogue or
  • show a clickable download button

but I don't know how to implement either. Can you help me?

Aucun commentaire:

Enregistrer un commentaire