【发布时间】:2021-11-08 10:05:36
【问题描述】:
我正在尝试为客户端提供在 Flask 中下载某些文件的选项。用户/客户端可以下载多个文件或单个文件。
但是我不明白如何为用户提供下载多个文件的选项。
这是我迄今为止尝试过的:
@app.route('/download_files')
def download():
count=0
download_list=[]
for path in pathlib.Path("dir1/dir2").iterdir():
if path.is_file():
for i in names:
if pathlib.PurePosixPath(path).stem == i:
count += 1
download_list.append(path)
return send_file(download_list, as_attachment=True, mimetype="text/plain", download_name="Downloaded Files", attachment_filename="Generated Files")
即使使用单个文件,这也无法正常工作。我要下载的文件类型是扩展名为 .sql 的文本文件。
我是否必须以某种方式压缩多个文件,然后提供下载选项?请指导我的可用选项。
【问题讨论】:
标签: python html file flask download