question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Authentication (Token check) before file upload

See original GitHub issue

How can i check ouath2 token before the file is uploaded?

In the current configuration the file is uploaded and then the dependency is called to check the token. Instead of wasting resources untill the file is completely uploaded (especially if it’s a big file) I would like to check the token before it completes the upload

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def upload_file(
        user_id=Depends(verify_access_token),
        ufiles: UploadFile = File(...),
):
    return {"Hello": "World"}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
bezacacommented, May 4, 2021

Have you tried using an asynchronous function for this case ?

0reactions
jziolkowskicommented, May 8, 2021

But does it really depend on the actual endpoint/middleware? Isn’t the file upload being the part of the request? Therefore only if the file is uploaded, the request is “complete” and sent to the server? I think that this is part of how HTTP works, not fastapi itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authenticate Web API session before body upload
Authentication is a simple challenge/response system using a token, so this means a client could easily upload several hundred megabytes of data ...
Read more >
How to upload a file through an API? - YouTube
How to upload a file through an API? | Token -based Authentication. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >
File upload / download and Basic / Bearer authentication ...
Before testing this example, you must full fill following requirements ; 1. Generate private and public keys pair in same directory as (testkey...
Read more >
Authentication using Databricks personal access tokens
Bearer authentication. You can use this approach with ; curl or any client that you build. For the latter, see Upload a big...
Read more >
Verify ID Tokens | Firebase Authentication - Google
Before you begin · Retrieve ID tokens on clients · Verify ID tokens using the Firebase Admin SDK · Verify ID tokens using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found