Skip to content

Commit

Permalink
fix for download filename in front , see #40
Browse files Browse the repository at this point in the history
  • Loading branch information
yjmantilla committed Aug 21, 2021
1 parent 4082694 commit 6229dbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion front/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def convert():
@app.route("/download", methods=["GET"])
def download():
files = getListOfFiles(app.config['CONV_FOLDER'])
return download_files(files)
return download_files(files,os.path.join(app.config['TEMP_FOLDER'],'the_zip.zip'))
# return make_response(jsonify({'data': files}))

def getListOfFiles(dirName):
Expand Down
23 changes: 11 additions & 12 deletions front/app/download_zip.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import os
import zipfile
from io import BytesIO

from flask import send_file
from flask import Response

def download_files(list_files):
# list_files = [
# "/home/leobahm/Escritorio/l7-back-end/media/users/documents/Rut_aQTaQ3I.pdf"
# ]
def download_files(list_files,filename):
zip_subdir = "archivos"
zip_filename = "%s.zip" % zip_subdir
s = BytesIO()
zf = zipfile.ZipFile(s, "w")
#s = BytesIO()
zf = zipfile.ZipFile(filename, "w")

for fpath in list_files:
zip_path = fpath.split("_convert\\")[-1]

# Add file, at correct path
#zf.write(os.path.join(path,fpath), zip_path)
zf.write(fpath, zip_path)

# Must close zip for all contents to be written
zf.close()
name = 'bids-converted_dataset.zip'
#response = Response(s.getvalue(), content_type = "application/x-zip-compressed")
#response['Content-Disposition'] = 'attachment; filename= "%s"' % filename

response = Response(s.getvalue(), content_type = "application/x-zip-compressed")
# See https://stackoverflow.com/a/53390515/14068216
response = send_file(filename, mimetype="application/x-zip-compressed", attachment_filename=name, as_attachment=True)
response.headers["x-filename"] = name
response.headers["Access-Control-Expose-Headers"] = 'x-filename'
# # ..and correct content-disposition
# response['Content-Disposition'] = 'attachment; filename=%s' % zip_filename

Expand Down

0 comments on commit 6229dbe

Please sign in to comment.