How to download a file htmx way? #2741
Unanswered
wojciech-mazur-mlg
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
AFAIK, the common technique to trigger a file download without user interaction from javascript is by creating a dummy hidden link with a <a href="/generate-file" download
_="click me, on click remove me"> <!-- I don't know hyperscript's syntax, consider this pseudo code -->Instead of your current div, and use hyperscript to trigger a Clicking the link will trigger your browser's native file download popup with the progress bar showing, so I wouldn't worry about the lack of hx-indicator in this case as the browser itself will show progress for that download. Hope this helps! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
We are developing a web app using python FastAPI and htmx. We have a scenario of generating a file to download which seems to be quite common, but we don't know how to handle it correctly (in an interactive way) using htmx.
The scenario should look like this:
/downloadendpointhx-indicator)This is the desired scenario, but the biggest limitation is that htmx can't return a file, we need to issue "full" request to get a file.
Our current implementation is like this:
/downloadendpoint/downloadendpoint returns a partial html with toast message and this div:/generate-fileendpoint which should return a proper file using FastAPI StreamingResponse./generate-fileendpoint (but it's regular request with no HX-Request) and the file is generated and returned correctly....butIs there a proper way to handle such scenario? Do you have any ideas? Thank for any help.
Beta Was this translation helpful? Give feedback.
All reactions