Flask proxy response for file download Flask proxy response for file download flask flask

Flask proxy response for file download


This can be done with the Content-Disposition HTTP header. Here you can specify a filename for the newly downloaded file.

This can be added to a Flask Response as follows:

url = "http://cdn.gea.esac.esa.int/Gaia/gaia_source/csv/GaiaSource_000-{:03d}-{:03d}.csv.gz".format(series,req = requests.get(url, stream=True)headers = Headers()headers .add('Content-Type', req.headers["content-type"])headers .add('Content-Disposition', 'attachment; filename="filename.txt"')return Response(stream_with_context(req.iter_content(chunk_size=2048)), headers=headers)

Note: The Content-Type was moved into headers for simplicity