【发布时间】:2021-07-22 07:47:18
【问题描述】:
我目前在子域上有一个应用程序,名为 api.example.com,并且我有 example.com 将带有 api.example.com 的文件放入 HTML 流文件中,而不是发送它以供下载。
HTML 看起来是这样的
<a href="https://api.example.com/path/to/file" download="https://api.example.compath/to/file">
我也试过了
<a href="https://api.example.com/path/to/file" download>
我的烧瓶路线是这样的
CORS(app, headers='Content-Type')
@app.route('/static/downloads/<path:path>')
def generic_send_file(path):
final_name = path.split('/')[-1]
return send_from_directory(
app.config['DOWNLOAD_FOLDER'],
path,
as_attachment=True,
attachment_filename=final_name
)
我的 nginx 路由是这样的
server_name api.example.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /home/www/api/static/;
}
client_max_body_size 100000m;
这是我的独角兽
[program:api]
command = /home/www/env/bin/gunicorn run:app -b localhost:8000
environment=PATH="/home/www/env/bin:%(ENV_PATH)s"
directory = /home/www/api
user = api
stdout_logfile = /var/log/api/api.out.log
stderr_logfile = /var/log/api/api.err.log
flask 应用在本地运行。但是当我把它上线时,它不是发送 mp3 文件来下载,而是在浏览器中打开它。
任何帮助将不胜感激。
【问题讨论】: