You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to upload a file using FormData but it fails with
{"code":"InputStreamIncorrectLengthException","message":"The length of the file input stream does not match the provided length. Expected: '12463', Actual (approximate): '12464.'"}
As I am not setting the Content-Length manually but its set internally by node-fetch, I want to raise this here.
PS: I also tried setting the Content-Length manually to 12463, 12464 and 12465 (the actual length of the UInt8Array) but none worked either
Reproduction
I am using the following code from within a VSCode extension
let formData: FormData = new FormData();
const fileName = uri.path.split('/').pop().split(".")[0];
const arr: Uint8Array = await vscode.workspace.fs.readFile(uri);
const blob: Blob = new Blob([arr]);
formData.append(fileName, blob);
let headers = this._headers;
headers["Content-Type"] = "multipart/form-data";
const config: RequestInit = {
method: "POST",
headers: headers,
body: formData
};
let response: Response = await fetch(endpoint, config);
Expected behavior
Content-Length should be set correctly automatically when using FormData
the code is similar to whats described in the docs: const abc = new File([binary], 'abc.txt', { type: 'text/plain' })
Your Environment
software
version
node-fetch
3.3.2
node
v18.13.0
npm
8.19.3
Operating System
Windows 11
The text was updated successfully, but these errors were encountered:
unclear if it's a similar issue. but the services i was using is also expectin a multipart/form-data body but was responding with bad request. I then just omitted the content-type for sanity and it seemed to work, this was how the samples used it
I want to upload a file using FormData but it fails with
As I am not setting the
Content-Length
manually but its set internally bynode-fetch
, I want to raise this here.PS: I also tried setting the
Content-Length
manually to 12463, 12464 and 12465 (the actual length of the UInt8Array) but none worked eitherReproduction
I am using the following code from within a VSCode extension
Expected behavior
Content-Length
should be set correctly automatically when using FormDatathe code is similar to whats described in the docs: const abc = new File([binary], 'abc.txt', { type: 'text/plain' })
Your Environment
The text was updated successfully, but these errors were encountered: