How do I zip an entire folder (with subfolders) and serve it through Flask without saving anything to disk
import timefrom io import BytesIOimport zipfileimport osfrom flask import send_file@app.route('/zipped_data')def zipped_data(): timestr = time.strftime("%Y%m%d-%H%M%S") fileName = "my_data_dump_{}.zip".format(timestr) memory_file = BytesIO() file_path = '/home/data/' with zipfile.ZipFile(memory_file, 'w', zipfile.ZIP_DEFLATED) as zipf: for root, dirs, files in os.walk(file_path): for file in files: zipf.write(os.path.join(root, file)) memory_file.seek(0) return send_file(memory_file, attachment_filename=fileName, as_attachment=True)