Skip to content

2.0.0

Choose a tag to compare

@octet-stream octet-stream released this 10 Dec 09:10

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