Skip to content

form data file name not being preserved through a request in jsdom #9260

@RyanClementsHax

Description

@RyanClementsHax

Describe the bug

When a file name is given to a File object and attached to a Request through a FormData object, the file name given is lost.

I've tracked the issue down to this line of code

return new NodeBlob_([buffer], { type: blob.type })

where it doesn't copy over the file name if there is one. It is likely that this line was intended to only execute this code for Blobs, but File is a subclass of Blob.

if (value instanceof window.Blob) {

Reproduction

test("file name preserves through a request", async () => {
    const fileName = "my-doc.pdf"
    const file = new File([new Uint8Array(1_024)], fileName, {
        type: "application/pdf",
    })
    const formData = new FormData()
    formData.append("file", file, fileName)
    const request = new Request("http://example.com", {
        body: formData,
        method: "POST",
    })
    const result = await request.formData()
    expect(result.get("file").name).toEqual(fileName)
})

System Info

System:
    OS: Linux 5.15 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (8) x64 AMD EPYC 7R13 Processor
    Memory: 27.18 GB / 30.67 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 24.12.0 - /home/coder/.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /home/coder/.nvm/versions/node/v24.12.0/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^5.1.2 => 5.1.2 
    @vitest/coverage-v8: ^4.0.15 => 4.0.15 
    vite: ^7.2.7 => 7.3.0 
    vitest: ^4.0.15 => 4.0.15

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions