Skip to content

Releases: octet-stream/form-data

2.0.1

28 Dec 15:06
Compare
Choose a tag to compare

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


All changes: v2.0.0...v2.0.1

2.0.0

10 Dec 09:10
Compare
Choose a tag to compare

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 is Buffer, Blob-ish or File-ish object, its own properties will be used to get the size.

Update

  • 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 51e01a7;

  • Fix for a field content-type header #8 (dfd5ad1);

  • Improve error messaging and arguments checking for FormData#{set,append}() methods.


All changes: v1.8.1...v2.0.0

1.8.1

24 Sep 19:53
Compare
Choose a tag to compare

Update:

  • Fix a typo for default content type

All changes: v1.8.0...v1.8.1

1.8.0

04 Jul 10:48
Compare
Choose a tag to compare

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

13 Jun 23:34
Compare
Choose a tag to compare

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