python – How dispatch an after_this_request signal after post request is done in flask

I’m trying to dispatch an after_this_request signal in Flask after a post request is done.

@v2.route("/", methods=("GET", "POST"))
def receive():
    if request.method == "GET":
        return "You must provide an IFC file!"
    else:
        if "ifc" not in request.files:
            return "You must provide an IFC file!"
        else:
            ifc = request.files["ifc"]
            ifcfilename = f"{shortuuid.uuid()}.ifc"

            ifcpath = os.path.join(current_app.config["UPDIR"], ifcfilename)

            ifc.save(ifcpath)

            @after_this_request
            def dispatch(response):
                process(ifcpath, request.form)
                return response

            return "File IFC ricevuto con successo!"

The process signal is made like this:

def process(ifc, body):
    print(ifc)
    print(body

The fact is that return "File IFC ricevuto con successo!" will never be send to the client until after the process function is excecuted!

How do I save a file return a response and then make the signal start?

Read more here: Source link