V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Zuckonit
V2EX  ›  问与答

bottle.py 如何提供文件下载

  •  
  •   Zuckonit · May 23, 2014 · 3616 views
    This topic created in 4362 days ago, the information mentioned may be changed or developed.
    不是很熟悉, 请教下大家。

    @route('/download/<hash>')
    def download_file(hash): pass


    比如写成这种restful形式, 当用户访问带hash的连接的时候下载对应文件, 服务器的response该怎么写?
    passluo
        1
    passluo  
       May 23, 2014   ❤️ 1
    return static_file(filename, root='/path/to/static/files')
    Shared
        2
    Shared  
       May 23, 2014
    建议配合 nginx 之类的服务器程序提供静态文件的下载功能,要不就楼上的方法
    Zuckonit
        3
    Zuckonit  
    OP
       May 23, 2014
    @passluo 刚刚试了下,多谢, 不过还要加个download=True参数, 默认的是False
    passluo
        4
    passluo  
       May 23, 2014   ❤️ 1
    嗯,查查看官方文档上的说明。
    Zuckonit
        5
    Zuckonit  
    OP
       May 23, 2014
    @passluo 直接看的代码T. T 哈哈
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2571 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 07:01 · PVG 15:01 · LAX 00:01 · JFK 03:01
    ♥ Do have faith in what you're doing.