Fastapi 返回文件下载

# -*- coding: UTF-8 -*-

# pip3 install aiofiles==0.5.0

from fastapi import FastAPI
from starlette.responses import FileResponse


app = FastAPI()


@app.get("/file")
def file():
    return FileResponse('./readme.txt', filename='test.txt')


if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, host='127.0.0.1', port=8002)

你可能感兴趣的:(python)