Skip to content

Instantly share code, notes, and snippets.

@devpilot
Created December 14, 2021 04:28
Show Gist options
  • Save devpilot/1a0a478f12405cf79f735ac3b1e7915e to your computer and use it in GitHub Desktop.
Save devpilot/1a0a478f12405cf79f735ac3b1e7915e to your computer and use it in GitHub Desktop.
Demo api for zip download
from flask import Flask, send_file, make_response
import zipfile
import io
import pathlib
app = Flask(__name__)
@app.route("/download",methods=['GET'])
def request_zip():
base_path = pathlib.Path('./data/')
data = io.BytesIO()
with zipfile.ZipFile(data, mode='w') as z:
for f_name in base_path.iterdir():
z.write(f_name)
data.seek(0)
response = make_response(
send_file(
data,
mimetype='application/zip',
as_attachment=True,
attachment_filename='logs.zip'
)
)
response.headers['Access-Control-Allow-Origin'] = '*'
return response
if __name__ == '__main__':
app.run(host='0.0.0.0',port = 8090, threaded = True, debug = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment