r/FastAPI • u/Impressive_Ad_1738 • Aug 28 '24
Question Reading File Via Endpoint
Hi everyone, I'm an intern and I'm new to FastAPl.
I have an endpoint that waits on a file, to keep it simple, I'll say the endpoint is designed like this
async def read_file (user_file: UploadFile=File (...)): user_file_contents = await user_file.read() return Response(content=user_file_contents)
For smaller files, this is fine and fast, for larger files, about 50MB, it takes about 30 seconds to over a minute before the full document can be received by the endpoint and processed.
Is there a way to speed up this process or make it faster? I really need this endpoint to work under or around seconds or ms
Any help would be appreciated, thank you!
View all comments
Show parent comment
2
u/Impressive_Ad_1738 Aug 28 '24
Its not the response that's taking too long, it's for the whole file to be read/received initially. I set up some traces for that endpoint and 1/4 of the time taken for that endpoint is from it receiving the document.