-
-
Notifications
You must be signed in to change notification settings - Fork 605
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
Allow passing local file path to ui.download #1118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the PR:
- For consistency I chose to use
helpers.is_file
for checking ifsrc
is a local file. - I moved the definition of
DOWNLOAD_DIR
out of test_helpers.py, because this file isn't meant to be a place for "test helpers", but rather a file testing the helpers.py file. - I don't approve the PR, yet, because there is a potential memory leak: For every download there is a new route added to the FastAPI app. Now there are two cases:
- There are different file, e.g. captured images. Every download of the current image creates a new route which is never cleaned up, even if the image is eventually removed from memory.
- There is some button like a "Download the datasheet of our great product" triggering the download of a local PDF. Each client clicking the button will create another route with the same path. For a well visited website this might eventually be a significant leak.
So I wonder if there's an alternative to avoid accumulating routes.
You are right. |
Maybe we can create a unique route if the download is executed and remove it after the file has been served. Kind of a one-time-download-route. We do something similar in https://github.com/zauberzeug/nicegui/blob/main/examples/download_text_as_file/main.py. |
# Conflicts: # tests/test_download.py
@rodja I implemented such single-use download routes. Have a look. 🙂 Test code: ui.button('Download', on_click=lambda: ui.download('website/static/logo.png'))
l = ui.label()
ui.timer(1, lambda: l.set_text(len(app.routes))) |
Super cool :-) |
This PR enhances the
ui.download
element to also work with local file paths (likeui.image
etc)