How can I use fixed-length multipart request with FormData?
See original GitHub issueDiscussed in https://github.com/nodejs/undici/discussions/1420
<div type='discussions-op-text'>Originally posted by nwtgck May 6, 2022
Hi, I’d like to request a fixed-length multipart request. The code below requested with transfer-encoding: chunked
without content-length. I assume the length of formData is statically decided.
const undici = require("undici");
(async () => {
const formData = new undici.FormData();
formData.append("myname", "myvalue");
const res = await undici.request("http://localhost:8181", {
body: formData,
});
})();
$ nc -lp 8181
PUT / HTTP/1.1
host: localhost:8181
connection: keep-alive
content-type: multipart/form-data; boundary=----formdata-undici-0.5140957512643098
transfer-encoding: chunked
64
------formdata-undici-0.5140957512643098
Content-Disposition: form-data; name="myname"
myvalue
2a
------formdata-undici-0.5140957512643098--
0
```</div>
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Set content-length header on individual parts of a multipart ...
To construct the POST request in javascript I use a FormData object and append the File objects for the upload to it. This...
Read more >Multipart Form Post in C# - Brian Grinstead
I first tried using the WebClient UploadFile method, but it didn't fit my needs because I wanted to upload form values (id, filename,...
Read more >Multipart formposts - Everything curl
A multipart formpost is what an HTTP client sends when an HTML form is submitted with enctype set to "multipart/form-data". It is an...
Read more >multipart/form-data - AndreuBotella.com
The multipart/form-data chunk serializer takes an entry list entries and an optional encoding encoding (default UTF-8), and returns a tuple of a ...
Read more >1434553 - Content-Length is wrong for multipart/form-data ...
When a DOM Blob/File object is sent to the server in a multipart form submission, we take its inputStream, and, together with other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems like the issue is that the spec is unclear https://fetch.spec.whatwg.org/#concept-bodyinit-extract
https://github.com/nodejs/undici/blob/8549a9402c46034d6d28b2f6f65d934736e51a59/lib/fetch/body.js#L114-L115
I checked Firefox and it looks like they do set the length in their implementation https://searchfox.org/mozilla-central/rev/8dd35cd8f5284fbaa506aab02fe42fc87efb249e/dom/html/HTMLFormSubmission.cpp#373
hmm. couldn’t really convert the formdata to a blob as i’m doing in node-fetch and the formdata polyfill for browsers I’m using
fetch-blob
instead that can accept 3rd party blobs backed up by the fs. And i couldn’t really use theFileLike
as it did only accept one blob part instead of an array of parts.https://github.com/nodejs/undici/blob/860c2617ba55d911286f967dbc915f03e89e0d94/lib/fetch/file.js#L95-L97
So it’s not spec compatible in that regards…