Flask: Example how to send zip file downloaded from other page.
Example shows how to use BytesIO to download zip file from other page and send it to web browser without saving on disk.
from flask import Flask, send_file
import requests
import io
app = Flask(__name__)
@app.route('/')
def index():
# get file from other page
response = requests.get('https://github.com/furas/mate-python-applets/archive/master.zip')
# create file in memory
zip_content = io.BytesIO(response.content)
# send it to client - it needs `as_attachment` to change name with `attachment_filename`
return send_file(zip_content, mimetype='application/zip', as_attachment=True, attachment_filename='archive.zip')
if __name__ == '__main__':
app.run()
If you like it
Buy a Coffee
furas.pl