Hi, I am trying to stream file upload, however it seems granian/emmett doesn't handle it properly.
I am expecting granian/emmett to stream the body when calling file.stream.read
and only keeps a reasonable buffer size.
However it seems granian/emmett does the following instead
To reproduce, upload file, watch log print and check memory usage:
emmett==2.5.13
granian==1.5.2
def get_size(file):
size = 0
while True:
chunk = file.stream.read(16 * 1024)
if not chunk:
break
print(size)
size += len(chunk)
return size
@app.route("upload")
async def upload():
if request.method == "POST":
files = await request.files
file = files.file
await asyncio.to_thread(get_size, file)
return {}
btw, it seems emmett is reading the full file into BytesIO?
emmett/emmett/wrappers/request.py
Lines 96 to 102 in 7014464
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too