I want to stream and download file using aiohttp
.
Chrome can support the resume capability of download link
But the download manager cannot download the file with the resume capability.
In the code below I used aiohttp framework to stream and download the file, I've also set the header parameter ('Accept-Ranges') to support resume capability.
from telethon import TelegramClient, events
client = TelegramClient(name, api_id,api_hash)
@routes.get('/{userid}/{msgid}')
async def handle(request):
...
response = web.StreamResponse(
status=200,
reason='OK',
headers={
'Content-Type': content_type,
'Content-Length':str(file_size),
'Accept-Ranges': 'bytes',
'Connection': 'keep-alive',
}
)
await response.prepare(request)
async for chunk in client.iter_download(msg.media, chunk_size=512):
await response.write(chunk)
return response
app = web.Application()
app.add_routes(routes)
web.run_app(app,host='0.0.0.0')
When the download link is hit in the browser,the file is well streamed.
Resume capability is well supported in Chrome,
I expect the download manager to be well supported resume capability, but after the pause hits and starts downloading again,download manager unable to continue downloading and requires user to restart download.
The message IDM
gives: "When trying to resume the download, internet download manager got response from the server that it does not support resuming the download ..."