Skip to content

FileUpload: onRemove does not correctly return the removed file if it has already been uploaded. #7808

@alequisk

Description

@alequisk

Describe the bug

I was using the FileUpload component in advanced mode when I needed to create a custom method to remove files from the database. I noticed that when trying to remove an already uploaded file, it returned undefined for the "file" key.

Analyzing the component, I found that the method responsible for removing an uploaded file mistakenly selects the array of files that are yet to be uploaded.

Reproducer

No response

System Information

System:
    OS: Linux 6.8 Linux Mint 22 (Wilma)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400
    Memory: 43.78 GB / 62.58 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 22.6.0 - ~/.nvm/versions/node/v22.6.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.6.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v22.6.0/bin/npm
    pnpm: 9.7.1 - ~/.local/share/pnpm/pnpm
  Browsers:
    Brave Browser: 133.1.75.180
    Chrome: 133.0.6943.126
  npmPackages:
    primereact: ^10.9.2 => 10.9.2 
    react: ^19.0.0 => 19.0.0 
    tailwindcss: ^4.0.12 => 4.0.12

Steps to reproduce the behavior

  1. Add the element file upload in advanced mode
<FileUpload
    name="files"
    url={`http://localhost:8000/upload`}
    accept="application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    mode="advanced"
    multiple
    onRemove={event => console.log(event)}
    ref={uploadFileRef}
/>
  1. Upload some file and click send button
  2. When click in remove, notice that the console will display an object, and inside it, you will see the following content:
file: undefined,
originalEvent: original event,

Expected behavior

return the event with the props file with the respective file removed

Object[
file: File,
originalEvent: original event,
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Needs TriageIssue will be reviewed by Core Team and a relevant label will be added as soon as possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions