I need to open the previously loaded file into the next function. I have this code which works great:
@app.post("/uploadFile")
async def create_upload_file(file: UploadFile = File(...)):
with open(f'{file.filename}', "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
return {"filename": file.filename}
@app.post("/v1/ingestion")
async def root():
with open('test_file.json') as file:
db = json.load(file)
return {"message": db}
I need to read the file.filename instead of the test_file.json, which is hard-coded. Is this possible?
I found this answer, it seems useful, but I don't know how to use it in the asynchronous functions like the ones in my examples. Could you please help me ?
Thanks a lot!