You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
@Time : 2023/3/30 14:16
|
|
@Author :
|
|
@FileName:
|
|
@Software:
|
|
@Describe:
|
|
"""
|
|
from flask import send_file, send_from_directory
|
|
from flask import Flask, jsonify
|
|
import os
|
|
from flask import request
|
|
from flask import make_response
|
|
|
|
app = Flask(__name__)
|
|
app.config["JSON_AS_ASCII"] = False
|
|
|
|
|
|
# @app.route('/download', methods=["GET", "POST"])
|
|
# def download():
|
|
# path = './new_data_txt/大型商业建筑人员疏散设计研究(1).docx'
|
|
# return send_file(path,
|
|
# as_attachment=True,
|
|
# download_name="大型商业建筑人员疏散设计研究(1).docx")
|
|
#
|
|
# # rv.headers['Content-Disposition'] += "; filename*=utf-8''{}".format(filename)
|
|
|
|
|
|
@app.route("/download/<filename>", methods=['GET'])
|
|
def download_file(filename):
|
|
# 需要知道2个参数, 第1个参数是本地目录的path, 第2个参数是文件名(带扩展名)
|
|
directory = './new_data_txt/' # 假设在当前目录
|
|
|
|
response = make_response(send_from_directory(directory, filename, as_attachment=True))
|
|
response.headers["Content-Disposition"] = "attachment; filename={}".format(filename.encode().decode('latin-1'))
|
|
return response
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=14009, threaded=True, debug=False)
|