-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Labels
Description
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.15Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.