StreamingResponse start download while waiting for data #2622
Unanswered
valeriodeblasio-1
asked this question in
Q&A
Replies: 1 comment
-
This won't work. I confirmed that most browsers handle the download dialog after receiving some real content (excluding markup like chunked encoding). Even fairly large chunk extensions are ignored, so they expect real content, not just bytes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to send a file to a user, however the file is generated asynchronously via a thread which can take a long time (even 30 seconds).
I would like the browser to show the file being downloaded right away (with 0 bytes and unknown size), tried via cUrl and it works but with a browser (Chrome or Firefox) this doesn't happen, the download only starts after the first bytes have been sent.
The only way I've been able to find is to send empty characters (\u200B) while waiting for the file to be generated (as suggested in this similar problem Chrome doesn't show file as being downloaded until 8 bytes are sent (Firefox does)), but this way the resulting file contains these characters at the beginning, which then gives problems when loading on other systems.
Another method is to use "Content-Type": "application/force-download", but it works only on Chrome (and as is not a standard MIME I don't know if it will broke something)
this is an example code
Beta Was this translation helpful? Give feedback.
All reactions