Skip to content
Advertisement

How to send a dynamically generate zipfile to the client

I am looking for a way to send a zipfile to the client that is generated from a requests response. In this example, I send a JSON string to a URL which returns a zip file of the converted JSON string.

JavaScript

But my zip file is empty and the error returned by flask is

JavaScript

Advertisement

Answer

You should return the file directly, not a ZipFile() object:

JavaScript

The response you receive is indeed a zipfile, but there is no point in having Python parse it and give you unzipped contents, and Flask certainly doesn’t know what to do with that object.

Advertisement