Frage

I followed the tutorial to stream a file generated on the fly in Flask. Now I want to display a message using the same data that was used to generate the file. It's a large dataset and I can not afford to download it both to generate the file and print a result on the page.

Unlike In Flask how can I redirect to a template and show a message after returning send_file in a view? , I do not want a redirect or a refresh. Is it possible to send both a file and HTML response in a single page load?

I tried using a generator but did not have any success.

I am using Heroku.

War es hilfreich?

Lösung

You're trying to return a "multipart HTTP response", with a HTML part and another (the file) part. After a quick research I'm not sure such a thing exists, and if it does how it is supported/implemented in browsers.

A slightly different way to that would be to respond with a "classic" HTML response which would then fire a second request, a XHR call at document load for instance, to start the download of the file.

Server side you would have to store the content of the file, I'm not really familiar with Heroku, but I guess you could use a key-value like Redis to do so, or even a dedicated service like Amazon S3.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top