Open jennydaman opened 1 month ago
Reproducible with Bun (1.1.31+e448c4cc3).
Is there any reason you don't set the file name directly at the third parameter to set()
or append()
?
Here I am presenting a minimal reproduction of the bug. In my actual use case, I found that a package I was using behaved differently from node on bun. The package wraps axios and FormData without providing a way to customize how either are used.
Of course, axios itself is a wrapper around node's http module so a more minimal reproduction is possible.
If you set(name, blobValue, filename)
or append(name, blobValue, filename)
the filename
directly the expected result is achieved.
async function main() {
const formData = new FormData();
const blob = await new Response(formData).blob();
formData.set("fname", new Blob(["hello, world"], {type: "text/plain", }), "blob");
await fetch("http://localhost:7777", {method: 'POST', body: formData, headers: {
"Content-Type": blob.type
},});
}
main();
nc -l -p 7777
POST / HTTP/1.1
content-type: multipart/form-data; boundary="-WebkitFormBoundary7c9e7ef531cb4055a2eee908443c44df"
Connection: keep-alive
User-Agent: Bun/1.1.31
Accept: */*
Host: localhost:7777
Accept-Encoding: gzip, deflate, br
Content-Length: 231
---WebkitFormBoundaryb88376d3bb39427cb2b93b1919d1d1ac
Content-Disposition: form-data; name="fname"; filename="blob"
Content-Type: text/plain;charset=utf-8
hello, world
---WebkitFormBoundaryb88376d3bb39427cb2b93b1919d1d1ac--
While this language is on MDN
Optional
The filename reported to the server (a string), when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
the language
The default filename for Blob objects is "blob".
is not in the specification.
I think setting the file name to "blob"
for the case of no filename
explicitly set is by convention of stakeholders, that you might be able to find in issues in W3C, WHATWG repositories and in tests on WPT.
What version of Bun is running?
1.1.29+6d43b3662
What platform is your computer?
Linux 6.11.3-arch1-1 x86_64 unknown
What steps can reproduce the bug?
Either using axios:
Or fetch:
Create a server listening on port 7777, e.g. using
nc
:What is the expected behavior?
Whether using
fetch
oraxios
,node
will setfilename="blob"
Request using axios:
Using
fetch
:What do you see instead?
Using bun and axios:
Notice how
filename
is missing completely.Or using fetch:
Additional information
Possibly related to https://github.com/oven-sh/bun/issues/7917