{"id":16845261,"url":"https://github.com/jimmywarting/formdata","last_synced_at":"2025-05-14T20:02:25.622Z","repository":{"id":44939679,"uuid":"71378225","full_name":"jimmywarting/FormData","owner":"jimmywarting","description":"HTML5 `FormData` polyfill for Browsers and nodejs","archived":false,"fork":false,"pushed_at":"2024-03-06T09:18:04.000Z","size":448,"stargazers_count":358,"open_issues_count":4,"forks_count":102,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-06T09:05:15.393Z","etag":null,"topics":["formdata","html5","polyfill"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimmywarting.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["jimmywarting"],"custom":["https://paypal.me/jimmywarting","https://jimmy.warting.se/opensource"]}},"created_at":"2016-10-19T16:41:21.000Z","updated_at":"2025-03-12T12:57:44.000Z","dependencies_parsed_at":"2024-06-18T11:27:32.321Z","dependency_job_id":null,"html_url":"https://github.com/jimmywarting/FormData","commit_stats":{"total_commits":180,"total_committers":21,"mean_commits":8.571428571428571,"dds":"0.18888888888888888","last_synced_commit":"820421ba9ee291cbf6b1b21aaa14ae1846d7c66c"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmywarting%2FFormData","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmywarting%2FFormData/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmywarting%2FFormData/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmywarting%2FFormData/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimmywarting","download_url":"https://codeload.github.com/jimmywarting/FormData/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717243,"owners_count":21150388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formdata","html5","polyfill"],"created_at":"2024-10-13T12:58:08.886Z","updated_at":"2025-04-13T12:47:30.428Z","avatar_url":"https://github.com/jimmywarting.png","language":"JavaScript","readme":"\u003e **Note:** FormData is built in to NodeJS v18 globally so that you no longer need this.\n\n### A `FormData` polyfill for the browser ...and a module for NodeJS (`New!`)\n\n```bash\nnpm install formdata-polyfill\n```\n\nThe browser polyfill will likely have done its part already, and i hope you stop supporting old browsers c\",)\u003cbr\u003e\nBut NodeJS still lacks a proper FormData\u003cbr\u003eThe good old form-data package is a very old and isn't spec compatible and does some abnormal stuff to construct and read FormData instances that other http libraries are not happy about when it comes to follow the spec.\n\n### The NodeJS / ESM version\n- The modular (~2.3 KiB minified uncompressed) version of this package is independent of any browser stuff and don't patch anything\n- It's as pure/spec compatible as it possible gets the test are run by WPT.\n- It's compatible with [node-fetch](https://github.com/node-fetch/node-fetch).\n- It have higher platform dependencies as it uses classes, symbols, ESM \u0026 private fields\n- Only dependency it has is [fetch-blob](https://github.com/node-fetch/fetch-blob)\n\n```js\n// Node example\nimport fetch from 'node-fetch'\nimport File from 'fetch-blob/file.js'\nimport { fileFromSync } from 'fetch-blob/from.js'\nimport { FormData } from 'formdata-polyfill/esm.min.js'\n\nconst file = fileFromSync('./README.md')\nconst fd = new FormData()\n\nfd.append('file-upload', new File(['abc'], 'hello-world.txt'))\nfd.append('file-upload', file)\n\n// it's also possible to append file/blob look-a-like items\n// if you have streams coming from other destinations\nfd.append('file-upload', {\n  size: 123,\n  type: '',\n  name: 'cat-video.mp4',\n  stream() { return stream },\n  [Symbol.toStringTag]: 'File'\n})\n\nfetch('https://httpbin.org/post', { method: 'POST', body: fd })\n```\n\n----\n\nIt also comes with way to convert FormData into Blobs - it's not something that every developer should have to deal with.\nIt's mainly for [node-fetch](https://github.com/node-fetch/node-fetch) and other http library to ease the process of serializing a FormData into a blob and just wish to deal with Blobs instead (Both Deno and Undici adapted a version of this [formDataToBlob](https://github.com/jimmywarting/FormData/blob/5ddea9e0de2fc5e246ab1b2f9d404dee0c319c02/formdata-to-blob.js) to the core and passes all WPT tests run by the browser itself)\n```js\nimport { Readable } from 'node:stream'\nimport { FormData, formDataToBlob } from 'formdata-polyfill/esm.min.js'\n\nconst blob = formDataToBlob(new FormData())\nfetch('https://httpbin.org/post', { method: 'POST', body: blob })\n\n// node built in http and other similar http library have to do:\nconst stream = Readable.from(blob.stream())\nconst req = http.request('http://httpbin.org/post', {\n  method: 'post',\n  headers: {\n    'Content-Length': blob.size,\n    'Content-Type': blob.type\n  }\n})\nstream.pipe(req)\n```\n\nPS: blob \u0026 file that are appended to the FormData will not be read until any of the serialized blob read-methods gets called\n...so uploading very large files is no biggie\n\n### Browser polyfill\n\nusage:\n\n```js\nimport 'formdata-polyfill' // that's it\n```\n\nThe browser polyfill conditionally replaces the native implementation rather than fixing the missing functions,\nsince otherwise there is no way to get or delete existing values in the FormData object.\nTherefore this also patches `XMLHttpRequest.prototype.send` and `fetch` to send the `FormData` as a blob,\nand `navigator.sendBeacon` to send native `FormData`.\n\nI was unable to patch the Response/Request constructor\nso if you are constructing them with FormData then you need to call `fd._blob()` manually.\n\n```js\nnew Request(url, {\n  method: 'post',\n  body: fd._blob ? fd._blob() : fd\n})\n```\n\nDependencies\n---\n\nIf you need to support IE \u003c= 9 then I recommend you to include eligrey's [blob.js]\n(which i hope you don't - since IE is now dead)\n\n\u003cdetails\u003e\n    \u003csummary\u003eUpdating from 2.x to 3.x\u003c/summary\u003e\n\nPreviously you had to import the polyfill and use that,\nsince it didn't replace the global (existing) FormData implementation.\nBut now it transparently calls `_blob()` for you when you are sending something with fetch or XHR,\nby way of monkey-patching the `XMLHttpRequest.prototype.send` and `fetch` functions.\n\nSo you maybe had something like this:\n\n```javascript\nvar FormData = require('formdata-polyfill')\nvar fd = new FormData(form)\nxhr.send(fd._blob())\n```\n\nThere is no longer anything exported from the module\n(though you of course still need to import it to install the polyfill),\nso you can now use the FormData object as normal:\n\n```javascript\nrequire('formdata-polyfill')\nvar fd = new FormData(form)\nxhr.send(fd)\n```\n\n\u003c/details\u003e\n\n\n\nNative Browser compatibility (as of 2021-05-08)\n---\nBased on this you can decide for yourself if you need this polyfill.\n\n[![screenshot](https://user-images.githubusercontent.com/1148376/117550329-0993aa80-b040-11eb-976c-14e31f1a3ba4.png)](https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility)\n\n\n\nThis normalizes support for the FormData API:\n\n - `append` with filename\n - `delete()`, `get()`, `getAll()`, `has()`, `set()`\n - `entries()`, `keys()`, `values()`, and support for `for...of`\n - Available in web workers (just include the polyfill)\n\n  [npm-image]: https://img.shields.io/npm/v/formdata-polyfill.svg\n  [npm-url]: https://www.npmjs.com/package/formdata-polyfill\n  [blob.js]: https://github.com/eligrey/Blob.js\n","funding_links":["https://github.com/sponsors/jimmywarting","https://paypal.me/jimmywarting","https://jimmy.warting.se/opensource"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmywarting%2Fformdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimmywarting%2Fformdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmywarting%2Fformdata/lists"}