oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.35k stars 2.78k forks source link

Multipart: Boundary not found #15306

Open 7flash opened 1 day ago

7flash commented 1 day ago

What version of Bun is running?

1.1.34+5e5e7c60f

What platform is your computer?

Linux 6.8.0-31-generic x86_64 x86_64

What steps can reproduce the bug?

function sendFile(filePath, jwt) {
    const file = Bun.file(filePath);
    if (!(await file.exists())) throw new Error(`file not found ${filePath}`);

    form.append("file", file);
    form.append("pinataOptions", '{\n  "cidVersion": 1\n}');
    console.debug(1732170353, Bun.inspect(form));

    const options = {
      method: "POST",
      headers: { Authorization: `Bearer ${jwt}`, "Content-Type": "multipart/form-data" },
    };

    options.body = form;

    const uploadResult = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", options);

    const resData = await uploadResult.json();

    console.debug(1732169936, resData);
}

What is the expected behavior?

expected to work accordingly to examples in test/js/web/html/FormData.test.ts

What do you see instead?

Image

Additional information

No response

RiskyMH commented 19 hours ago

Could be related to #7917, but it's hard to say for certain since the API server you mentioned requires an auth token.

Manually specifying the Content-Type header might also be contributing to the issue, as multipart/form-data typically includes a boundary parameter. This is usually applied automatically when using FormData, so overriding it manually could cause unexpected behavior.