I’ve been trying to use the sanic streaming branch (because of issues in the current streaming), but am having trouble with streaming a put request to aiofiles. Can someone tell me if I am doing this incorrectly or if this is an unresolved issue in the new branch?
The file gets created, but is always empty. I can’t see that any chunk is ever received when trying to write to aiofiles.
@app.route("/<id:uuid>/<version:int>/<part:int>", methods=["PUT"],stream=True)
async def put_version_part(request,id,version,part):
versionfolder = Path(app.config['storage_folder']) / str(id) / str(version)
tf = versionfolder / 'parts'
filename = f"data.{part}"
try:
os.makedirs(tf)
except FileExistsError:
pass
async with aiofiles.open(tf/filename, 'wb') as f:
while True:
chunk = await request.stream.read()
if not chunk:
break
await f.write(chunk)
f.close()
return JSONResponse({'id':str(id),'version':version, 'part':part}, status=201)