【发布时间】:2016-08-02 15:10:15
【问题描述】:
我需要下载文件,这是通过 AJAX 触发的。我的代码从临时文件夹中的 URL 检索图像,并在此临时文件夹中创建文件的内存 zip。我想将文件路径推送到客户端。我该怎么做?
这是我的邮政编码:
#This function creates a temp folder, downloads images in it and returns the path
temp_dir = retrieve_images(file_paths)
in_memory_loc = io.BytesIO()
zipf = zipfile.ZipFile(, 'w')
zipdir(temp_dir, zipf)
zipf.close()
#remove the temp directory
shutil.rmtree(temp_dir)
in_memory_loc.seek(0)
#output the zip file to the browser
return send_file(in_memory_loc, attachment_filename='site_images.zip', as_attachment=False)
这在我使用传统的表单提交方式时有效。但我需要通过 AJAX 返回它。通过 AJAX 返回文件似乎是不可能的,因此我想返回 zip 文件路径。我该怎么做?
【问题讨论】:
-
我可能会考虑从这个问题中删除代码和 Python 标记,因为据我所知,这是一个与 Python 或 zip 文件无关的一般网络问题。
-
是的,但我使用的语言是 Python。人们通常倾向于为他们编码的语言找到答案!
标签: jquery python ajax flask zip