首页 > 技术文章 > fastapi实现页面文件下载功能

itBlogToYpl 2020-07-04 17:09 原文

from starlette.responses import FileResponse


@app.get("/download/{file_name}")
def main(file_name: str):
    print(file_name)
    basedir = os.path.abspath(os.path.dirname(__file__))
    path = basedir + '\\' + str(datetime.datetime.now().date())
    file_path = path + '\\' + file_name + '.xlsx'
    print(file_path)
    return FileResponse(file_path)

 

推荐阅读