如何select flask send_file 中的下载位置?
How to select the download location in flask send_file?
我正在开发一个基于 UI 的烧瓶,我正在使用 send_file 函数下载一个文本文件。
这是我的目录设置:
/static
/design.css
/templates
/index.html
/upload.html
/engine.html
/output
/text_file.txt
/main.py
代码如下:
@app.route('/download')
def download_file():
path = "output\text_file.txt"
return send_file(path, as_attachment=True)
下面是启动下载的相关 html 按钮:
<button>
<a href="{{ url_for('.download_file') }}" style="color: white; text-decoration: none;">Download Source Text
</a>
</button>
现在这个功能是直接下载我本地C盘downloads文件夹中的文件。但我想获得 select 位置的选项,如下所示:
(图片取自google)
我该如何实现?
下载文件的保存路径由浏览器决定,服务器端应用程序无法更改——这是一个特性,不是错误。
你想一想——假设服务器应用程序可以选择一个位置来保存文件,如果我的网站将一个 exe 文件保存到你的 C:\Windows 文件夹中怎么办?后果不堪设想...
一些现代浏览器允许用户设置默认下载路径。如果您发现您的文件被保存到一个文件夹,例如 Downloads
,而没有询问您,很可能是您启用了此浏览器功能。
我正在开发一个基于 UI 的烧瓶,我正在使用 send_file 函数下载一个文本文件。
这是我的目录设置:
/static
/design.css
/templates
/index.html
/upload.html
/engine.html
/output
/text_file.txt
/main.py
代码如下:
@app.route('/download')
def download_file():
path = "output\text_file.txt"
return send_file(path, as_attachment=True)
下面是启动下载的相关 html 按钮:
<button>
<a href="{{ url_for('.download_file') }}" style="color: white; text-decoration: none;">Download Source Text
</a>
</button>
现在这个功能是直接下载我本地C盘downloads文件夹中的文件。但我想获得 select 位置的选项,如下所示:
(图片取自google)
我该如何实现?
下载文件的保存路径由浏览器决定,服务器端应用程序无法更改——这是一个特性,不是错误。
你想一想——假设服务器应用程序可以选择一个位置来保存文件,如果我的网站将一个 exe 文件保存到你的 C:\Windows 文件夹中怎么办?后果不堪设想...
一些现代浏览器允许用户设置默认下载路径。如果您发现您的文件被保存到一个文件夹,例如 Downloads
,而没有询问您,很可能是您启用了此浏览器功能。