reflex
reflex copied to clipboard
[REF-2157] rx.download doesn't work with rx.get_upload_url from a backend event handler
Describe the bug
I want to write a file to a path obtained via rx.get_upload_dir() and then cause the user to download it via rx.download, but it doesn't work.
To Reproduce
import reflex as rx
class State(rx.State):
button_text: str = "Download"
def do_download(self):
filename = "foo.txt"
(rx.get_upload_dir() / filename).write_text("test")
return rx.download(rx.get_upload_url(filename))
@rx.page()
def index():
return rx.button(State.button_text, on_click=State.do_download)
app = rx.App()
Expected behavior Download the file that we write in the event handler
Instead, exception
Traceback (most recent call last):
File "/Users/masenf/code/reflex-dev/reflex/reflex/state.py", line 1439, in _process_event
events = fn(**payload)
^^^^^^^^^^^^^
File "/Users/masenf/code/reflex-dev/repro-download-from-upload-dir/repro_download_from_upload_dir/repro_download_from_upload_dir.py", line 8, in do_download
return rx.download(rx.get_upload_url(filename))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/masenf/code/reflex-dev/reflex/reflex/event.py", line 589, in download
raise ValueError("The URL argument should start with a /")
ValueError: The URL argument should start with a /
Specifics (please complete the following information):
- Python Version: 3.11.4
- Reflex Version: 0.4.4a1
- OS: macOS
- Browser (Optional):
Additional context Add any other context about the problem here.
hello, is it possible that this is no longer working with more recent versions? i can download a file in "/assets" but not in "/uploaded_files" using a very similar code to what you have in the bug description. thank you
hello, is it possible that this is no longer working with more recent versions?
yes it appears to be broken in 0.6.0+