question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I use fixed-length multipart request with FormData?

See original GitHub issue

Discussed 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:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

0reactions
jimmywartingcommented, Dec 18, 2022

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 the FileLike 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…

import { fileFromSync } from 'fetch-blob/from.js'

const fsFile = fileFromSync('file.txt')
const fd = new globalThis.FormData()
fd.set('a', fsFile)
const FileLike = fd.get('a').constructor
new FileLike(['a', 'b']) // don't work...
new FileLike([blob, blob]) // don't work either...
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found