Sanic response file() 实现文件下载功能,提供文件下载接口


0x00 脚本说明

Sanic使用response file()实现文件下载功能,提供文件下载接口。

0x01 功能代码

from sanic import Sanic
from sanic import response


app = Sanic()


@app.route('/file')
async def file(request):
    return await response.file(
        './welcom-to-猿人学.jpg',
        headers={'X-Serverd-By': 'YuanRenXue Python'}
    )


if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8888, debug=True)

0x02 参考文章

https://www.yuanrenxue.com/sanic/sanic-response-file.html