# multipart-formdata

> A zero-dependency multipart/form-data parser

Latest version **1.1.0** (published 2018-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install multipart-formdata
pnpm add multipart-formdata
yarn add multipart-formdata
bun add multipart-formdata
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-01-12 |
| First published | 2018-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Cristian Salazar |
| Maintainers | sschadwick |
| Keywords | multipart/form-data, multipart, form-data, form, fileuploader, upload |

## Links

- npm: https://www.npmjs.com/package/multipart-formdata
- Repository: https://github.com/UWFosterIT/multipart-formdata
- Homepage: https://github.com/UWFosterIT/multipart-formdata#readme
- Issues: https://github.com/UWFosterIT/multipart-formdata/issues
- npm.io page: https://npm.io/package/multipart-formdata

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-01-12

## README

# multipart-formdata

A zero-dependency multipart/form-data parser.

### Background

Sometimes you only have access to the raw multipart payload and need it to be
parsed in order to extract files or data.

Example: Using a serverless api such as `claudia-api-builder` with AWS Api-Gateway/Lambda.

The raw payload formatted as multipart/form-data will looks like this one:

```
// req.body

------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads"; filename="somebinary.dat"
Content-Type: application/octet-stream

some binary data...maybe the bits of a image..
------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads"; filename="sometext.txt"
Content-Type: text/plain

hello world
------WebKitFormBoundaryDtbT5UpPj83kllfw--
```

The lines above represent a raw multipart/form-data payload sent by an HTTP client via form submission containing two files. The multipart parser allows us to separate the files and extract header information.

### Usage

* `req.body`

```
------WebKitFormBoundaryDtbT5UpPj83kllfw
Content-Disposition: form-data; name="uploads[]"; filename="sometext.txt"
Content-Type: application/octet-stream

hello how are you
------WebKitFormBoundaryDtbT5UpPj83kllfw--
```

* boundary, the unique string which serve as a 'separator' between parts, normally parsed from headers. In this case, the boundary is:

```
	----WebKitFormBoundaryDtbT5UpPj83kllfw
```


* Example implementation

```javascript
	var multipart = require('parse-multipart');
	var body = "..the multipart raw body..";
	var boundary = "----WebKitFormBoundaryDtbT5UpPj83kllfw";
	var parts = multipart.parse(body, boundary);

  /*
  console.log(parts);

	[{
		data:     <Buffer 41 41 41 41 42 42 42 42>,
		field:    '',
		filename: 'A.txt',
		name:     'file',
		type:     'text/plain',
	}, ...];
	*/
```

The returned data is an array of objects, each with a filename, any data fields, field name, content-type and data properties. The data prop is a Buffer (see also Node Buffer).

---
_Source: https://npm.io/package/multipart-formdata · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
