0

I want to time how long it takes to upload a file to a Flask app. I am trying to use something like this to know when the upload starts:

@app.before_request
def before_request():
    g.start = time.time()

However, before_request fires only after the full request (file) has been uploaded, so at most, all I can measure how long it takes to process the uploaded file.

Is there another signal/decorator I can use to determine when a Request has been initiated, even before the full request is available? (ie when a user starts to upload a file, but before it begins?)

hamx0r
  • 4,081
  • 1
  • 33
  • 46
  • Yes, you can stack decorators. Most elegant way is to write your own timer decorator. See this post: https://stackoverflow.com/a/27737385/12060936 – Grzegorz Pudłowski Mar 18 '20 at 00:22

1 Answers1

0

I am not sure whether I am correct, just guessing here.

Flask is not the web server itself, it only servers as a CGI application. My guess is the web server (e.g. the dev server you use or an Apache HTTP server) is able to know whether a request has arrived, and it will receive the file. When it is completed, it will dispatch the request to Flask.

DrizzleX
  • 377
  • 3
  • 11
  • I think you're likely right @DrizzleX . I can't find anything in Flask docs to trigger _before_ a request is dispatched, only `before_request` to fire after dispatching and before handling (to be clear, there is a trigger before dispatching when using Blueprints, but even then, then Flask app has the full request in hand). – hamx0r Mar 18 '20 at 19:45