欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python下载文件

程序员文章站 2022-04-08 23:16:55
...
from flask import Flask,request,Response

app = Flask(__name__)

@app.route('/', methods=["GET"])
def download():
    file = request.args.get("file", 0)
    f = open(file,'r')
    data = f.read()
    f.close()

    return Response(data, content_type='application/octet-stream',headers={
        'Content-Disposition':'attachment; filename={}'.format(f.name)
    })

if __name__ == '__main__': 
    app.run(host='0.0.0.0',
            threaded=True,
            debug=False,
            port=8080)