I have an endpoint in FastAPI that receives json data and file from client. My main goal is to secure this endpoint since receiving files without validation could be risky. I have to make validation before uploading file and tried dependency injection. Is "Depends" function enough to prevent file uploading and if not what are the alternatives? Note: I cannot make the validation in client-side code so do not consider that as an option please.
My current program gives uuid to proper clients and checks the uuid using Depends function. It works for now but i am not certain that if the file is still uploaded before depends or not. This is the code(the json data contains string and dict. these are extracted from the fields below):
async def validate_uuid(uuid: str):
if uuid == "a valid uuid":
print("success")
return uuid
else:
print("fail")
raise HTTPException(status_code=400, detail="UUID invalid")
@app.post("/file")
async def file_upload(
request: Request, response: Response, file: UploadFile = File(...), check_uuid: str = Depends(validate_uuid), dict_data: dict
):
#do smth