The purpose of this app is to demonstrate how CSV (or any other file, for that matter) can be sent to browser (to download) in stream. We use Rails and Angular here but the logic is more or less the same for any other frameworks.
Sometimes generating a file takes too long, and long server calls aren't always handled well by the browser or the platform (i.e. Heroku timeouts any requests that take longer than 30 seconds).
Streaming the file contents after sending the initial response to the browser solves it.
The magic happens in two places:
client/src/app/app.component.ts— the download function makes a synchronous call to the server. It generates a form dinamically for that purpose.app/controllers/export_controller.rb— the server part.
The server part is borrowed from this Bernardo Farah's article.
bundle install
cd client && npm install
cd client
npm run build
cd ..
rm public/main*
rm public/polyfills*
rm public/styles*
rm public/inline*
cp -rf client/dist/* public/
rails s
Go to localhost:3000 and click on the red button.