Releases: octet-stream/form-data
2.0.1
Update
- 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
}
}
])
Remove
@octetstream/invariant
is not necessary for this package anymore so I did removed it from dependencies
All changes: v2.0.0...v2.0.1
2.0.0
Remove
- Drop Node.js 8 support. The minimal supported version is now 10.
Add
-
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 isBuffer
,Blob
-ish orFile
-ish object, its own properties will be used to get the size.
Update
-
FormData
now storesBuffer
andBlob
-ish objects like aFile
-ish.
So, when you use theFormData#{get,getAll}()
methods or iterate through FormData values
you will getFile
-ish object instead ofBlob
,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 51e01a7;
-
Improve error messaging and arguments checking for
FormData#{set,append}()
methods.
All changes: v1.8.1...v2.0.0
1.8.1
1.8.0
Add
-
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)
Update
- Bump dependencies.
All changes: v1.7.0...v1.8.0
1.7.0
Add
- Typings to use for TypeScript and some tests for them
- Node 12 in CI config
Update
- Bump dependencies
- Improve docs
All changes: 63620db...202b39a