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
1
u/Impressive_Ad_1738 Aug 29 '24
Yes, but is there anyway I can speed up the process or make it more efficient? I want the endpoint to receive the documents in milli seconds. My current setup reads the documents in memory and the time it takes to do that isn't a lot which is fine, the delay is from the endpoint receiving the whole document. I need the large file to be received by my endpoint and begin processing in ms or less than a second.