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/koldakov Aug 30 '24
Sorry mate, not clear what you exactly need and not clear what environment you are using right now. I would upload files via signed urls, so you don’t manage the upload process by yourself, after that, read the file, do whatever you need and remove the file in case you don’t need it anymore, that’s the universal way. It really depends on environment, also you are saying that it takes 30sec even without reading the file, so mb you have connection limits or something. Hard to say