reflex icon indicating copy to clipboard operation
reflex copied to clipboard

File upload error when a substate is used

Open rushenpatel opened this issue 2 years ago β€’ 1 comments

Describe the bug Issue when testing out the file upload utility. The given example works fine out of the box (if my State class inherits directly from pc.State) but if a base state is used an error is thrown on the FE.

To Reproduce Steps to reproduce the behavior:

import pynecone as pc


class State(pc.State):
    """The base state."""


class IndexState(State):
    """The app state."""

    # The image to show.
    img: str

    async def handle_upload(self, file: pc.UploadFile):
        """Handle the upload of a file.

        Args:
            file: The uploaded file.
        """
        upload_data = await file.read()
        outfile = f".web/public/{file.filename}"

        # Save the file.
        with open(outfile, "wb") as file_object:
            file_object.write(upload_data)

        # Update the img var.
        self.img = file.filename


def index():
    """The main view."""
    return pc.vstack(
        pc.upload(
            pc.button("Select File"),
            pc.text("Drag and drop files here or click to select files"),
            border="1px dotted black",
            padding="20em",
        ),
        pc.button(
            "Upload",
            on_click=lambda: IndexState.handle_upload(pc.upload_files())
        ),
        pc.image(src=IndexState.img),
    )


# Add state and page to the app.
app = pc.App(state=State)
app.add_page(index, title="Upload")
app.compile()

Expected behavior File uploads as when state class inherits from pc.State.

Screenshots Screenshot from 2023-03-06 15-09-30

** Specifics (please complete the following information):**

  • Python Version: 3.10
  • Pynecone Version: 0.1.19
  • OS: Ubuntu 22.04
  • Browser (Optional): Firefox

rushenpatel avatar Mar 06 '23 15:03 rushenpatel

Got it thanks for pointing out will fix this

Alek99 avatar Mar 06 '23 19:03 Alek99