A zip file is written in 'download_data' and there is no error or download response upon returning.
Notes:
The printed data returned from the function appears to be zipfile data
I have not augmented or utilized download.stream or response.download and do not know whether it is necessary in this case
Please indicate what is missing in the following ajax call and/or controller function to spawn the zip file download.
jQuery.ajax({method:'get',url:'{{=URL('download_data')}}',
data:fileIDs,
success: function(){}
});
# function in web2py controller
def download_data():
import zipfile
import cStringIO
import contenttype as c
vars = request.vars
tempfile = cStringIO.StringIO()
temparchive = zipfile.ZipFile(tempfile, 'w', zipfile.ZIP_DEFLATED)
fileIDs = vars.values()
try:
for file_id in fileIDs:
file = db.files[file_id].file
fileLoc = db.files.file.retrieve_file_properties(file)['path'] + '/' + file
temparchive.writestr(db.files[file_id].file_name, open(fileLoc, 'rb').read())
finally:
temparchive.close() #writes
response.headers['Content-Disposition'] = 'attachment;filename=files.zip'
response.headers['Content-Type'] = 'application/zip'
rtn = tempfile.getvalue()
tempfile.close()
return rtn