reflex icon indicating copy to clipboard operation
reflex copied to clipboard

[REF-2157] rx.download doesn't work with rx.get_upload_url from a backend event handler

Open masenf opened this issue 1 year ago β€’ 2 comments

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.

REF-2157

masenf avatar Mar 08 '24 18:03 masenf

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

goncalog avatar Dec 03 '24 17:12 goncalog

hello, is it possible that this is no longer working with more recent versions?

yes it appears to be broken in 0.6.0+

masenf avatar Dec 03 '24 17:12 masenf