From 9847e8509564ced723435b88b3117f4bc1f551d5 Mon Sep 17 00:00:00 2001 From: zeroth Date: Wed, 14 Oct 2020 16:12:50 +0100 Subject: [PATCH] we can download a zip folder hehehe --- library.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/library.py b/library.py index 36218e6..8d92752 100644 --- a/library.py +++ b/library.py @@ -99,7 +99,7 @@ def test(): print("test") clicked=None bundle = "bundle.zip" - zipObj = ZipFile(bundle, 'w') + # zipObj = ZipFile(bundle, 'w') if request.method == "POST": # clicked=request.form['data'] @@ -108,23 +108,20 @@ def test(): print(listofselecteddocs) print("hola") - - # create a ZipFile object - + with ZipFile(bundle, 'w') as zipObj2: # Add multiple files to the zip - zipObj.write('static/files/'+listofselecteddocs[0]) - zipObj.write('static/files/'+listofselecteddocs[1]) - zipObj.write('static/default-files/hello.txt') - # close the Zip File - - # return render_template('test.html') - # return send_file(bundle, mimetype='application/zip', as_attachment=True, attachment_filename=bundle) - # TEST - # print("sending file...") - # result = send_file(bundle, as_attachment=True) - # print("file sent, deleting...") - # os.remove(bundle) - # return result - zipObj.close() - return send_file(bundle, mimetype='application/zip', attachment_filename="hello.zip", as_attachment=True) + + readmeabsname = 'static/default-files/hello.txt' + readmearcname = "hello.txt" + zipObj2.write(readmeabsname,readmearcname) + + for doc in listofselecteddocs: + absname = 'static/files/'+doc + print(doc) + arcname = os.path.basename(doc) + zipObj2.write(absname, arcname) + + + + return send_file(bundle, mimetype='application/zip', attachment_filename="bundle.zip", as_attachment=True)