Following the explanations given here FastAPI - How to read an json file while using UploadFile and there FastAPI runs api-calls in serial instead of parallel fashion I switched to threading instead of async.
I removed the await
s in my program and now get an error when trying to read the uploaded file:
RuntimeWarning: coroutine 'UploadFile.read' was never awaited
result = context.run(func, *args)
from fastapi import FastAPI, UploadFile
from fastapi.responses import JSONResponse
app = FastAPI()
def validate_configuration(config_file: UploadFile = File(...)):
try:
content = config_file.read() # used await before and now causes an attribute error
print(content)
configurations = yaml.safe_load(content.decode())
return JSONResponse(content={"message": "Done"}
except Exception as exc:
return JSONResponse(content={"error": str(exc)}, status_code=400)
But of course I cannot use await
anymore, because I am no longer using async
so what is the intended way to resolve this?