Bartłomiej 'furas' Burek
furas.pl
# prywatne notatki - Python, Linux, Machine Learning, etc.

Flask: Example how to send zip file downloaded from other page.

Example shows how to download zip file from other page and send it 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()
Książki: python-dla-kazdego-podstawy-programowania python-wprowadzenie python-leksykon-kieszonkowy python-receptury python-programuj-szybko-i-wydajnie python-projekty-do-wykorzystania black-hat-python-jezyk-python-dla-hackerow-i-pentesterow efektywny-python-59-sposobow-na-lepszy-kod tdd-w-praktyce-niezawodny-kod-w-jezyku-python aplikacje-internetowe-z-django-najlepsze-receptury