Skip to content
Advertisement

How do I zip an entire folder (with subfolders) and serve it through Flask without saving anything to disk

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:

JavaScript

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.

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement