NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #2401 most downloaded on npm
Spec-compliant FormData implementation for Node.js
Last release 3 years ago
no release in 18 months
Release timing varies
gaps range from 8 days to 9 months
Nearly every release is documented
notes for 55 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
9 years old
76 releases · first in 2017
996b4b5 Thanks @octet-stream ! - Remove removeComments from tsconfig.json
996b4b5 Thanks @octet-stream! - Remove removeComments from tsconfig.jsond88ffae Thanks @octet-stream ! - Remove tsup config and changelog from distro
d88ffae Thanks @octet-stream! - Remove tsup config and changelog from distroOne column per quarter.
32fa6da Thanks @octet-stream ! - Remove changeset config from distro
32fa6da Thanks @octet-stream! - Remove changeset config from distro324a9a5 Thanks @octet-stream ! - Drop node-domexception in favour of Node.js' builtins. Consider polyfilling DOMException if you want to run this pack
324a9a5 Thanks @octet-stream! - Drop node-domexception in favour of Node.js' builtins. Consider polyfilling DOMException if you want to run this package in older environment
324a9a5 Thanks @octet-stream! - Bring back CJS support via tsup. You can now import package in both ES and CJS modules
324a9a5 Thanks @octet-stream! - Drop web-streams-polyfill in favour of Node.js' builtins. Consider polyfilling ReadableStream if you want to run this package in older environment
47a3ff8 Thanks @octet-stream! - Add ReadableStream w/o Symbol.asyncIterator support in Blob
0f68880 Thanks @octet-stream! - Add typings tests to make sure FormData, Blob and File compatible with globally available BodyInit type
47a3ff8 Thanks @octet-stream! - Drop Node.js 16. Now minimal required version is 18.0.0
Update package.json for bundler module resolution
All changes: https://github.com/octet-stream/form-data/compare/v5.0.0...v5.0.1
Removed CommonJS support. This package is native ESM from now on;
entries argument from FormData constructor.FileFromPath.slice() method;File.webkitRelatedPath property (See v4.4.0 release for more info);File values in FormData.{append,set}() methods (See v4.4.0 release for more info);File (See v4.4.0 release for more info);https://github.com/octet-stream/form-data/compare/v4.3.3...v5.0.0
Bump web-streams-polyfill to 4.0.0-beta.3
All changes: https://github.com/octet-stream/form-data/compare/v4.4.0...v4.4.1
Backport File.webkitRelativePath property for better types compatibility with native FormData
Backport File.webkitRelativePath property for better types compatibility with native FormData
Backport improvements for instanceof checks on File object: It now will recognize File-ish objects and Files as File instance, but not Blob or Blob-ish objects:
Old behaviour:
import {Blob, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const blob = new Blob()
file instanceof Blob // -> true
file instanceof File // -> true
blob instanceof Blob // -> true
blob instanceof File // -> true
const fileLike = {
[Symbol.toStringTag]: "File",
name: "file.txt",
stream() { }
}
const blobLike = {
[Symbol.toStringTag]: "Blob",
stream() { }
}
fileLike instanceof Blob // -> true
fileLike instanceof File // -> true
blobLike instanceof Blob // -> true
blobLike instanceof File // -> true
New behaviour:
import {Blob, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const blob = new Blob()
file instanceof Blob // -> true
file instanceof File // -> true
blob instanceof Blob // -> true
blob instanceof File // -> false
const fileLike = {
[Symbol.toStringTag]: "File",
name: "file.txt",
stream() { }
}
const blobLike = {
[Symbol.toStringTag]: "Blob",
stream() { }
}
fileLike instanceof Blob // -> true
fileLike instanceof File // -> true
blobLike instanceof Blob // -> true
blobLike instanceof File // -> false
Backport File values normalization for better alignment with the spec. FormData instances will store Files added via .set() and .append() methods as is.
Old behaviour:
import {FormData, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const form = new FormData()
form.set("file", file) // will create a new File, then store that new object
form.get("file") === file // -> false
form.set("file", file, "renamed-file.txt") // will also create a new File (with the new name), then store that new object
form.get("file") === file // -> false
New behaviour:
import {FormData, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const form = new FormData()
form.set("file", file) // will store this File instance as is
form.get("file") === file // -> true
form.set("file", file, "renamed-file.txt") // will create a new File (with the new name), then store that new object
form.get("file") === file // -> false
All changes: https://github.com/octet-stream/form-data/compare/v4.3.3...v4.4.0
Backport File.webkitRelativePath property for better types compatibility with native FormData
Backport improvements for instanceof checks on File object: It now will recognize File-ish objects and Files as File instance, but not Blob or Blob-ish objects:
Old behaviour:
import {Blob, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const blob = new Blob()
file instanceof Blob // -> true
file instanceof File // -> true
blob instanceof Blob // -> true
blob instanceof File // -> true
const fileLike = {
[Symbol.toStringTag]: "File",
name: "file.txt",
stream() { }
}
const blobLike = {
[Symbol.toStringTag]: "Blob",
stream() { }
}
fileLike instanceof Blob // -> true
fileLike instanceof File // -> true
blobLike instanceof Blob // -> true
blobLike instanceof File // -> trueNew behaviour:
import {Blob, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const blob = new Blob()
file instanceof Blob // -> true
file instanceof File // -> true
blob instanceof Blob // -> true
blob instanceof File // -> false
const fileLike = {
[Symbol.toStringTag]: "File",
name: "file.txt",
stream() { }
}
const blobLike = {
[Symbol.toStringTag]: "Blob",
stream() { }
}
fileLike instanceof Blob // -> true
fileLike instanceof File // -> true
blobLike instanceof Blob // -> true
blobLike instanceof File // -> falseBackport File values normalization for better alignment with the spec. FormData instances will store Files added via .set() and .append() methods as is.
Old behaviour:
import {FormData, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const form = new FormData()
form.set("file", file) // will create a new File, then store that new object
form.get("file") === file // -> false
form.set("file", file, "renamed-file.txt") // will also create a new File (with the new name), then store that new object
form.get("file") === file // -> falseNew behaviour:
import {FormData, File} from "formdata-node"
const file = new File(["File content"], "file.txt")
const form = new FormData()
form.set("file", file) // will store this File instance as is
form.get("file") === file // -> true
form.set("file", file, "renamed-file.txt") // will create a new File (with the new name), then store that new object
form.get("file") === file // -> falseAll changes: v4.3.3...v4.4.0
Remove duplicate row from comparison table
Fix the way how the package exposes typings for the upcoming TypeScript version. Thanks to @jaydenseric for this fix. More information here: #48 ;
fileFromPath and fileFromPathSync functions.All changes: v4.3.1...v4.3.2
Fix typings to allow File constructor to take Iterable as fileBits argument;
File constructor to take Iterable<unknown> as fileBits argument;All changes: https://github.com/octet-stream/form-data/compare/v4.3.0...v4.3.1
Deprecate entries argument in FormData constructor, because it is not spec-compliant.
instanceof test via Symbol.hasInstance method;package.json using exports field (#46);entries argument in FormData constructor, because it is not spec-compliant.All changes: https://github.com/octet-stream/form-data/compare/v4.2.4...v4.3.0
Improve type casting for lastModified option in File constructor;
lastModified option in File constructor;All changes: https://github.com/octet-stream/form-data/compare/v4.2.3...v4.2.4
Minor improvements for Blob.stream() method;
Blob.stream() method;All changes: https://github.com/octet-stream/form-data/compare/v4.2.2...v4.2.3
Deprecate FileOptions interface in favour of FilePropertyBag;
FileOptions interface in favour of FilePropertyBag;All changes: https://github.com/octet-stream/form-data/compare/v4.2.1...v4.2.2
Update typings for FileLike interface and improve documentation.
All changes: https://github.com/octet-stream/form-data/compare/v4.2.0...v4.2.1
Replace entry point in module field in package.json, so it will now point to browser entry point. This should fix the issue with Rollup module resolut
module field in package.json, so it will now point to browser entry point. This should fix the issue with Rollup module resolution. See: #44All changes: https://github.com/octet-stream/form-data/compare/v4.1.0...v4.2.0
Port Blob from fetch-blob@3 and replace fetch-blob@2 package with our own implementation. Note that formdata-node will switch back to use fetch-blob o
Blob from fetch-blob@3 and replace fetch-blob@2 package with our own implementation. Note that formdata-node will switch back to use fetch-blob once we drop CommonJS. Our Blob implementation should be compatible with fetch-blob, so you can use either of them in FormData values. In terms of usage nothing is changed - you can import Blob as from formdata-node package:import {FormData, Blob} from "formdata-node" // This will now import our own Blob implementation instead of `node-fetch@2`
const form = new FormData()
form.set("file", new Blob(["Some ", "content"]))
web-streams-polyfill, so the overall installation size will increase by ≈393KB.All changes: https://github.com/octet-stream/form-data/compare/v4.0.1...v4.1.0
Improvements for File class spec-compliancy: Make sure File.name and File.lastModified properties read-only in runtime;
File class spec-compliancy: Make sure File.name and File.lastModified properties read-only in runtime;name argument in File constructor to string;lastModified option normalization in File constructor to mimic browsers implementation behaviour: When lastModified option is NaN it is interpreted as 0 in browsers;filename argument normalization for FormData.set() and FormData.append() methods.All changes: https://github.com/octet-stream/form-data/compare/v4.0.0...v4.0.1
[BREAKING] Remove builtin multipart/form-data encoder and all related methods. You need check if your HTTP client supports spec-compliant FormData in
multipart/form-data encoder and all related methods. You need check if your HTTP client supports spec-compliant FormData in Node.js and if it don't, then you can suggest them to implement multipart/form-data encoding or use form-data-encoder package;Buffer and ReadStream (the one you might create with fs.createReadStream), you can use Blob, fileFromPath and fileFromPathSync to replace them. Other async data sources are still supported - see documentation for more information;polyfill entry points;fileFromPath functions from main entry point:- import {fileFromPath, fileFromPathSync} from "formdata-node"
+ import {fileFromPath, fileFromPathSync} from "formdata-node/file-from-path"
This subpath is NOT available in browsers!
isFile from file-from-path subpath;- import {isFileLike} from "formdata-node"
+ import {isFile} from "formdata-node/file-from-path"
FormDataFieldValue type to FormDataEntryValue (TypeScript specific);filename argument passed with non-File value to set() or append();Closes #42 All changes: https://github.com/octet-stream/form-data/compare/v3.7.0...v4.0.0
Deprecate options argument in set and append methods;
browser.ts;Content-Type and Content-Length headers from FormData#headers getter;options argument in set and append methods;FormData#boundary property;All changes: https://github.com/octet-stream/form-data/compare/v3.6.4...v3.7.0
Update form-data-encoder to 1.4.3 version to improve spec compliance;
form-data-encoder to 1.4.3 version to improve spec compliance;All changes: https://github.com/octet-stream/form-data/compare/v3.6.3...v3.6.4
Update form-data-encoder to latest version;
form-data-encoder to latest version;All changes: https://github.com/octet-stream/form-data/compare/v3.6.2...v3.6.3
Fix path in browser field in package.json
browser field in package.jsonAll changes: https://github.com/octet-stream/form-data/compare/v3.6.1...v3.6.2
Rewrite browser.js module with TypeScript and introduce CJS and ESM versions of it;
browser.js module with TypeScript and introduce CJS and ESM versions of it;exports field in main package.json to expose compiled versions browser.js.All changes: https://github.com/octet-stream/form-data/compare/v3.6.0...v3.6.1
[EXPERIMENTAL] Introduce browser field in package.json (see #39 PR by @char0n). Node.js user will not be affected by this change.
browser field in package.json (see #39 PR by @char0n). Node.js user will not be affected by this change.domexpeption with node-domexception which is using DOMException class from Node.jsform-data-encoder package. Note that the encoding will be removed in v4, so you'll need a client that support spec-compatible FormData or form-data-encoder to handle the encoding.options.lastModified from fileFromPath and fileFromPathSync since it may have introduce DOMException error to be thrown.mime-types package to reduce the size of formdata-node and make fileFromPath and fileFromPathSync behaviour more compatible with File class;All changes: https://github.com/octet-stream/form-data/compare/v3.5.4...v3.6.0
Various improvements TS typings:
blobParts argument in file constructor to expect an array of unknown parts, because fetch-blob can perform automatic conversions if necessary;FileLike interface will expect type field to be presented, because every File and Blob has such field;All changes: https://github.com/octet-stream/form-data/compare/v3.5.3...v3.5.4
Fix for FormData#stream initialization
All changes: https://github.com/octet-stream/form-data/compare/v3.5.2...v3.5.3
Expose isFileLike helper for public usage
isFileLike helper for public usagefetch-blob to 2.1.2 version since it has a fix for checks with nullish values (null instanceof Blob)All changes: https://github.com/octet-stream/form-data/compare/v3.5.1...v3.5.2
Fix for .append() method behaviour: It should *always* append entries
.append() method behaviour: It should always append entriesAll changes: https://github.com/octet-stream/form-data/compare/v3.5.0...v3.5.1
This release is mostly about deprecation of an old spec-incompatible features of this package on its way to the next major release.
This release is mostly about deprecation of an old spec-incompatible features of this package on its way to the next major release.
polyfill.mjs and polyfill.js so they will not affect globalThis when File, Blob or FormData presented.FormData#stream, FormData#headers, FormData#getComputedLength() and FormData#[Symbol.asyncIterator]() will be removed in 4.x version, use formdata-node with HTTP clients that support spec-compatible form-data or use form-data-encoder to perform the serialisation manuallyThis is how serialisation would look like, when using form-data-encoder:
import {Readable} from "stream"
import fetch from "node-fetch"
import {FormData, fileFromPath} from "formdata-node"
+ import {Encoder} from "form-data-encoder"
const fd = new FormData()
fd.set("name", "John Doe")
fd.set("avatar", await fileFromPath("/path/to/an/avatar.png"))
- const options = {
- method: "post",
- headers: fd.headers,
- body: Readable.from(fd)
- }
+ const encoder = new Encoder(fd)
+
+ const options = {
+ method: "post",
+ headers: encoder.headers // Note that this property has both `Content-Type` and `Content-Length` headers in it, unlike FormData#headers which only has `Content-Type` header
+ body: Readable.from(encoder)
+ }
await fetch("https://httpbin.org/post", options)
You don't have to worry about the form-data serialisation if your HTTP client support spec-compatible form-data, but this may help you otherwise
Buffer and ReadStream in entry's value will be removed in 4.x version. So they're deprecated too. To append files to the formdata-node instances, use File, Blob, fileFromPath() or fileFromPathSync:This is how you'll append files from Buffer:
- import {FormData, Blob} from "formdata-node"
+ import {FormData, Blob, fileFromPathSync} from "formdata-node"
const fd = new FormData()
- fd.set("blob", Buffer.from("Some data in buffer"))
+ // Note that you don't have to convert a string into buffer first to use it in Blobs. The source of Buffer may vary depending on the context. This one is here just for an example.
+ const buffer = Buffer.from("Some data in buffer")
+ fd.set("blob", new Blob([buffer], {type: "text/plain"}))
Appending files using fileFromPath:
- import {createReadStream} from "fs"
- import {FormData} from "formdata-node"
+ import {FormData, fileFromPath} from "formdata-node"
const fd = new FormData()
- fd.set("file", createReadStream("/path/to/a/file"))
+ fd.set("file", await fileFromPath("/path/to/a/file")) // Or use `fileFromPathSync` if you need synchronous version
4.x.All changes: https://github.com/octet-stream/form-data/compare/v3.4.0...v3.5.0
Compatibility improvements for File: It should now throw TypeError when called with less than 2 arguments
application/octet-stream if File object does not have the value for type propertyBlob class from fetch-blob package to allow to use it right from the formdata-nodeAll changes: https://github.com/octet-stream/form-data/compare/v3.3.2...v3.4.0
Revert Buffer to File conversion changes.
All changes: https://github.com/octet-stream/form-data/compare/v3.3.1...v3.3.2
Fix for TypeScript typings in FileLike interface
All changes: https://github.com/octet-stream/form-data/compare/v3.3.0...3.3.1
Introduce fileFromPath an async version of fileFromPathSync: Creates a File referencing the one on a disk by given path.
fileFromPath an async version of fileFromPathSync: Creates a File referencing the one on a disk by given path.FormData#getComputedLength() became synchronous. No need to use await with this method anymore. This change was made because FormData converts ReadStream to a File instance, so this method will use File#size value to get the size instead of using fsPromises.stat on ReadStream#path.All changes: https://github.com/octet-stream/form-data/compare/v3.2.0...v3.3.0
Deprecate FormData#stream property and ReadStream in a field's value. Propose Readable.from(formData) and fileFromPathSync as the new alternatives.
FormData#delete() method (that was probably a regression): now it returns undefined instead of boolean which was the result of the internal Map#delete() call.FormData#stream property and ReadStream in a field's value. Propose Readable.from(formData) and fileFromPathSync as the new alternatives.form-data encoder and helpers.All changes: https://github.com/octet-stream/form-data/compare/v3.1.1...v3.2.0
Improvements for form-data encoder.
form-data encoder.All changes: https://github.com/octet-stream/form-data/compare/v3.1.0...v3.1.1
Improve options normalisation for File and Blob values.
All changes: https://github.com/octet-stream/form-data/compare/v3.0.0...v3.1.0
Drop Node v10 support. Since its end-of-life is near, I set Node v12 as minimal required version ahead of time.
formdata-node exposes few more classes and helpers: FormData, File and fileFromPathSync. Also, for TypeScript users there are few types available now. In brief:import FormData from "formdata-node" // < 3.x version
import {FormData, File, fileFromPathSync} from "formdata-node" // >= 3.x version
ReadableStream and Readable as field's value. Since the browser-side FormData doesn't allow to use streams as values, I also decided to remove them from formdata-node. But you are still able to use ReadStream as value – they will automatically converted to File, there's no more option.size parameter in FormData#{append,set}() too.All changes: https://github.com/octet-stream/form-data/compare/v2.5.0...v3.0.0
Fix filename priorities for Blob and File objects
All changes: https://github.com/octet-stream/form-data/compare/v2.4.0...v2.5.0
Fix returning value of the FormData#get() method for non-existent fields: it now returns null instead of undefined just like the browser implementatio
FormData#get() method for non-existent fields: it now returns null instead of undefined just like the browser implementations do.All changes: https://github.com/octet-stream/form-data/compare/v2.3.0...v2.4.0
Removed Babel from the project. All modules as been rewritten as CJS. The @babel/runtime package is no more included.
@babel/runtime package is no more included.All changes: https://github.com/octet-stream/form-data/compare/v2.2.2...v2.3.0
All changes: https://github.com/octet-stream/form-data/compare/v2.2.1...v2.2.2
All changes: https://github.com/octet-stream/form-data/compare/v2.2.1...v2.2.2
Fix for Blob filename retrieving
All changes: https://github.com/octet-stream/form-data/compare/v2.2.0...v2.2.1
Bump minimal required Node.js version to 10.17
FormData#streamFormData#getComputedLength() to match browsers behaviour: now it will return the length of the boundary when FormData has no fieldsnanoid with crypto.randomBytes in boundary generatorAll changes: https://github.com/octet-stream/form-data/compare/v2.1.4...v2.2.0
Fix for nanoid import that causes error in Catsby.js
All changes: https://github.com/octet-stream/form-data/compare/v2.1.3...v2.1.4
All changes: https://github.com/octet-stream/form-data/compare/v2.1.2...v2.1.3
All changes: https://github.com/octet-stream/form-data/compare/v2.1.2...v2.1.3
All changes: https://github.com/octet-stream/form-data/compare/v2.1.1...v2.1.2
All changes: https://github.com/octet-stream/form-data/compare/v2.1.1...v2.1.2
Fix default name for a Blob field
import FormData from "formdata-node"
import Blob from "fetch-blob"
const fd = new FormData()
const blob = new Blob(["Where's your motivation?"], {type: "text/plain"})
fd.set("file", blob)
fd.get("file").name // "blob"
All changes: https://github.com/octet-stream/form-data/compare/v2.1.0...v2.1.1
Improve form-data encoding algorithm to make it more spec-compliant
All changes: https://github.com/octet-stream/form-data/compare/v2.0.1...v2.1.0
Fix arguments passing in constructor allowing to set the options arguments for form-data fields given to constructor
import {createReadStream, statSync} from "fs"
import FormData from "formdata-node"
const fd = new FormData([
{
name: "file",
value: createReadStream("/path/to/file"),
// Here you can set field's options
options: {
size: statSync("/path/to/file").size
}
}
])
@octetstream/invariant is not necessary for this package anymore so I did removed it from dependenciesAll changes: https://github.com/octet-stream/form-data/compare/v2.0.0...v2.0.1
Drop Node.js 8 support. The minimal supported version is now 10.
FormData#{set,append}() now takes an optional 4th (or 3rd) argument – options:
type Options = {
size?: number,
type?: string,
lastModified?: number,
filename?: string
}
This argument is used to put additional information for stream values.
Streams will be considered as a File-ish objects when this option is set.
If given value is Buffer, Blob-ish or File-ish object, its own properties will be used to get the size.
FormData now stores Buffer and Blob-ish objects like a File-ish.
So, when you use the FormData#{get,getAll}() methods or iterate through FormData values
you will get File-ish object instead of Blob, File, Buffer and streams:
import fs from "fs"
import FormData from "formdata-node"
import Blob from "fetch-blob"
const fd = new FormData()
fd.set("buffer", Buffer.from("I beat Twilight Sparkle and all I got was this lousy t-shirt"))
fd.get("buffer") // -> File
fd.set("blob", new Blob(["I beat Twilight Sparkle and all I got was this lousy t-shirt"], {type: "text/plain"}))
fd.get("blob") // -> File
// The "size" option required for stream values if you want them to be set as a File
fd.set("readStream", fs.createReadStream("/path/to/some/file.txt"))
fd.get("readStream") // -> ReadStream
fd.set("readStream", fs.createReadStream("/path/to/some/file.txt"), {
size: fs.statSync("/path/to/some/file.txt").size
})
fd.get("readStream") // -> File
Fix a typo in default content-type value https://github.com/octet-stream/form-data/commit/51e01a7175f5b558f47ea84574728d69c31d6d90;
Fix for a field content-type header #8 (https://github.com/octet-stream/form-data/commit/dfd5ad1ceaa212067e946ae76e2c8c5c217c0afd);
Improve error messaging and arguments checking for FormData#{set,append}() methods.
All changes: https://github.com/octet-stream/form-data/compare/v1.8.1...v2.0.0
Fix a typo for default content type
Update:
All changes: https://github.com/octet-stream/form-data/compare/v1.8.0...v1.8.1
Allow to use FormData as a polyfill. Just improve module like so:
Allow to use FormData as a polyfill. Just improve module like so:
import "formdata-node/polyfill"
console.log(FormData) // => [Function: FormData]
console.log(global.FormData) // => [Function: FormData]
console.log(globalThis.FormData) // => [Function: FormData]
Blob, File and ReadableStream -like objects as a field value:
import FormData from "formdata-node"
import fetch from "node-fetch"
import Blob from "fetch-blob" // Or any other compatible Blob implementation
const fd = new FormData()
const blob = new Blob(["My hovercraft is full of eels"], {type: "text/plain"})
fd.set("someFiled", blob)
fd.get("someField") // => Blob
// Now we send it
fetch("https://httpbin/post", {
method: "post",
body: fd.stream,
headers: fd.headers
})
.then(response => response.json())
.then(console.log)
All changes: https://github.com/octet-stream/form-data/compare/v1.7.0...v1.8.0
Typings to use for TypeScript and some tests for them
All changes: https://github.com/octet-stream/form-data/compare/63620dbb3b1b6528591b57c08bfb1013a8414c69...202b39a41995fe2e2df6e07a98d53b67be0f5c94
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →