-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any means to download the file? #38
Comments
Solved it as: @ui.get('/config.json')
def config_json_response(request: requests.Request):
return responses.FileResponse(pathlib.Path.home().joinpath(DATA_MANAGER_DIRECTORY, CONFIG_FILENAME))
# somewhere later...
with ui.link(target='/config.json').classes(remove='underline').props('download=config.json'):
ui.button('Download configuration file').classes('my-2 mx-4') Is there any better way? |
Yes, the Using Wrapping a button inside a link seems a little weird. Combining a button with ui.button('Download', on_click=lambda e: ui.open('/some/route/file.json', e.socket)) Note that without providing the socket, every browser connected to the app would open the file, not only the one that triggered the click event. |
Thanks! I'll update and try that. The line about socket should be probably added to the documentation. It was unclear to me what that argument is for. UPD: your code opens the file contents in the browser instead of downloading it. UPD: my bad, had to add non-empty PS: That's funny, Firefox just reloads the page when I click the button. What's more weird, even if I type another URL in the address field, it just reloads the page and doesn't go away from |
Yeah, the documentation says "param socket: optional WebSocket defining the target client". That's maybe a little short. I'll add some clarification. I think whether the file is displayed or downloaded depends on the browser and/or file extension. Good to hear that you found a way to enforce the download. The Firefox behavior is weird. |
So it's not only me? I thought my Firefox extensions could play tricks on me. Oh well. |
I'd like to create a button which, when clicked, causes a file to be downloaded in the browser. To my understanding, in regular HTML this is handled by
href
attribute.I tried:
ui.button('Download configuration file').classes('my-2 mx-4').props('href=https://quasar.dev')
which, according to https://quasar.dev/vue-components/button#example--links, I thought, should cause the browser to issue GET request to go toquasar.dev
website. But there's no reaction after click.Or should it be handled with
ui.add_route
for serving the file andon_click=lambda: ui.open(route_url)
button argument?The text was updated successfully, but these errors were encountered: