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.

Drop support for Form-Data?

See original GitHub issue

form-data isn’t really spec compatible and it dose some abnormal stuff. I know many other libraries support it. But it increases the complexity to anyone who is building a http library if they decide to support it. They (we) need to learn how it works internally of how it can be read & streamed

I would like to emphasize that it’s better to follow the standards instead. Any spec’ed FormData impl shouldn’t need any documentation.

There are two other spec compatible FormData packages on npm that works grate on NodeJS

  1. There is my own formdata-polyfill
  2. And also formdata-node

Both of wish can support appending Blob/Files backed up by the FileSystem (and also blob-like items). Unlike form-data that can only append a one-time readable streams. A FormData should be re-useable if you want to clone the body for whatever reason. (our tests cases could use the same FormData instances - but this dose not work with form-data)

This means that all other http libraries out there needs to serialize the body themself, But fear not, there are packages out there also that can convert them

  • My formdata-polyfill have a utility function to convert any spec compatible FormData into a Blob so that can be posted instead formDataToBlob(formdata)
  • octet-stream have built a FormData Encoder
  • And we also have a encoder built in now into node-fetch itself to convert any spec compatible FormData. after the introduction of response.formData() support we now include formdata-polyfill and using formDataToBlob(fd).stream()

form-data have had a long time to address the read/modify parts but never got around to implement any those methods. That’s b/c it’s based on appending all entries directly into a readable stream, so they can’t iterated over or modified them.

So my proposal really is to:

  1. Stop supporting form-data
  2. Throw a error or warning message that form-data is no longer supported and also mention alternative packages
  3. Remove all hacks where we utilize form.getHeaders(), getBoundary(), getLength(), hasKnownLength() - A FormData size should always be known/calculated.

So what do you think? I would rather want this to be moved into a discussion but this repo haven’t enabled it (and i can’t do that)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
octet-streamcommented, Aug 4, 2021

Alternatives mentioned above. Both of them should work just fine with node-fetch v3

1reaction
jespertheendcommented, Aug 4, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

FormData.delete() - Web APIs - MDN Web Docs
The delete() method of the FormData interface deletes a key and its value(s) from a FormData object. Note: This method is available in...
Read more >
Since support for FormData.delete() is low, what's the ...
Only solution to this at present is to manually add the key/value in newly created formData and post that to server. //This is...
Read more >
FormData - The Modern JavaScript Tutorial
FormData objects can help with that. ... formData.delete(name) – remove the field with the given name ,; formData.get(name) – get the value ...
Read more >
form-data - npm
Starting version 3.x FormData has dropped support for node@4.x . License. Form-Data is released under the MIT ...
Read more >
Developers - Drop support for Form-Data? - - Bountysource
Drop support for Form-Data ? · My formdata-polyfill have a utility function to convert any spec compatible FormData into a Blob so that...
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