import flask
from flask import send_file, make_response
app = flask.Flask(__name__)
@app.route('/pdf/<report_id>', methods=['GET'])
def post(report_id):
headers = ("Content-Disposition", f"inline;filename={report_id}.pdf")
as_attachment = False
file_path ='/home/xxxxxxx/pdf/{}.pdf'.format(str(report_id))
response = make_response(send_file(filename_or_fp=file_path, as_attachment=as_attachment))
response.headers[headers[0]] = headers[1]
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9003)
访问链接:http://ip地址:9003/pdf/113179539 (report_id:113179539)
中心代码引用地址
|