Skip to content

@rx.event(background=True) is not supported for upload handler #4974

@EssamWisam

Description

@EssamWisam

Describe the bug
The code:

    @rx.event(background=True)
    async def handle_upload(self, files: list[rx.UploadFile]):
        async with self:
            self.uploading = True

        for file in files:
            # Schedule reading the file as a task
            upload_data = await file.read()

            outfile = Path(self.uploads_folder) / file.filename
            outfile.parent.mkdir(parents=True, exist_ok=True)

            with outfile.open("wb") as file_object:
                file_object.write(upload_data)

            # Do some preprocessing (removed)

        async with self:
            self.uploading = False

Along with:

 rx.upload(
            rx.cond(
                State.uploading,
                rx.spinner(),
                rx.button(
                    rx.icon(tag="upload", size=19),
                    class_name="bg-accent-9 hover:bg-accent-10 p-1.5 rounded-full transition-colors cursor-pointer",
                ),
            ),
            id="file_upload",
            class_name="flex items-center",
            on_drop=State.handle_upload(rx.upload_files(upload_id="file_upload")),
            style={
                "padding": "0 !important",
                "border": "none",
            },  # Ensure no extra margin
        ),

Results in the error:

raise UploadTypeError(
reflex.utils.exceptions.UploadTypeError: @rx.event(background=True) is not supported for upload handler `reflex___state____state.frontend___state____state.handle_upload`.

To Reproduce
Copy-paste the examples above

Expected behavior
Should work as indicated in the docs here https://reflex.dev/docs/events/background-events/. The page for uploading provides a method to track upload progress but here I am looking for uploading + preprocessing progress (just a boolean to now if its still going on).

Specifics (please complete the following information):

  • Python Version: 0.6.8
  • Reflex Version: 3.10
  • OS: Mac OS
  • Browser (Optional): Edge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions