2016-02-17 62 views
0

如何使用aiohttp/asyncio提供可下載文件?提供使用aiohttp服務器下載文件的選項

我使用:

async def route_function(request): 
    return web.Response(body=b"Test") 

只是簡單地提供內容。

+0

你是什麼意思*下載*?瀏覽器應該打開一個對話框來選擇保存位置? –

+0

@AndrewSvetlov不,只是立即下載。 – PascalVKooten

+0

如果長度大約500 MB,是否要下載相對較小的文件或其大小? –

回答

1

的內容處理標頭可以指示響應主體是 要下載作爲實際文件,而不是在 瀏覽器中顯示。 [*]

  • Content-Disposition: Attachment
  • Content-Disposition: Attachment;filename=some_file.xyz與文件名

隨着aiohttp:

from aiohttp import MultiDict 

async def route_function(request): 
    return web.Response(
     headers=MultiDict({'Content-Disposition': 'Attachment'}), 
     body=b"Test" 
    ) 
相關問題