I have a folder structure on my web server that I would like to serve as a zipped archive through Flask.
Serving a file through Flask is pretty straight forward through Flasks send_file:
return send_file(my_file,
attachment_filename=fileName,
as_attachment=True)
Zipping can get accomplished in various ways like with shutil.make_archive
or zipfile
, but i cannot figure out how to zip the whole directory in memory and then send it without saving anything to disk. shutil.make_archive
seem to only be able to create archives on disk. The examples on zipfile
found on the Internet are mainly about serving single files.
How would I tie this together in a single method without having to save everything to disk? Preferably using BytesIO
.