# parse-multipart

> A javascript/nodejs multipart/form-data parser which operates on raw data.

Latest version **1.0.4** (published 2017-05-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-05-24 |
| First published | 2017-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/parse-multipart) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 50 |
| Author | Cristian Salazar |
| Maintainers | csalazar |
| Keywords | multipart/form-data, form, fileuploader |

## Links

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

## 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.0.4 (latest) — 2017-05-24
- 1.0.3 — 2017-04-06
- 1.0.2 — 2017-04-05
- 1.0.1 — 2017-04-03
- 1.0.0 — 2017-04-03

## README

# parse-multipart

A javascript/nodejs multipart/form-data parser which operates on raw data.

# author

Cristian Salazar. Email: christiansalazarh@gmail.com, Website: www.chileshift.cl,
i live in Santiago de Chile. I am Amazon AWS developper focused in Serverless
software development, i call it: the new age of software development.

# Help & Tutorial

Please follow me on Twitter [@AmazonAwsVideos](https://twitter.com/amazonawsvideos) and keep informed about more Amazon Aws Videos. Watch my video on which i expose the necesary steps to [implement a Multiform/form-data parser inside a Amazon Aws ApiGateway](https://www.youtube.com/watch?v=BrYJlR0yRnw). You can [subscribe to my channel](https://www.youtube.com/c/ChristianSalazar).

# Background

Sometimes you only have access to the raw multipart payload and it needs to be
parsed in order to extract the files or data contained on it. As an example: 
the Amazon AWS ApiGateway, which will operate as a facade between the http
client and your component (the one written by you designed to extract the 
uploaded files or data). 

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

```
------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 how are you
------WebKitFormBoundaryDtbT5UpPj83kllfw--
```

The lines above represents a raw multipart/form-data payload sent by some 
HTTP client via form submission containing two files. We need to extract the 
all files contained inside it. The multipart format allows you to send more 
than one file in the same payload, that's why it is called: multipart.

# Usage

In the next lines you can see a implementation. In this case two key values
needs to be present:

* body, which can be:

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

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

* boundary, the string which serve as a 'separator' between parts, it normally
comes to you via headers. In this case, the boundary is:

```
	----WebKitFormBoundaryDtbT5UpPj83kllfw
```

Now, having this two key values then you can implement it:

```
	var multipart = require('parse-multipart');
	var body = "..the multipart raw body..";
	var boundary = "----WebKitFormBoundaryDtbT5UpPj83kllfw";
	var parts = multipart.Parse(body,boundary);
	
	for(var i=0;i<parts.length;i++){
		var part = parts[i];
		// will be:
		// { filename: 'A.txt', type: 'text/plain', 
		//		data: <Buffer 41 41 41 41 42 42 42 42> }
	}
```

The returned data is an array of parts, each one described by a filename,
a type and a data, this last one is a Buffer (see also Node Buffer).

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