# busboymiddleware

> Provide a simple middleware for file uploads, using busboy.

Latest version **1.4.0** (published 2014-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install busboymiddleware
pnpm add busboymiddleware
yarn add busboymiddleware
bun add busboymiddleware
```

## 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.4.0 |
| Published | 2014-10-10 |
| First published | 2014-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dmitri Gaskin |
| Maintainers | dmitrig01 |
| Keywords | upload, busboy |

## Links

- npm: https://www.npmjs.com/package/busboymiddleware
- Repository: https://github.com/BranchMetrics/BusboyMiddleware
- Issues: https://github.com/BranchMetrics/BusboyMiddleware/issues
- npm.io page: https://npm.io/package/busboymiddleware

## Dependencies (1)

- [busboy](https://npm.io/package/busboy.md) ^0.2.8

## Recent versions

- 1.4.0 (latest) — 2014-10-10
- 1.3.0 — 2014-07-18
- 1.2.0 — 2014-07-16
- 1.1.0 — 2014-07-16
- 1.0.0 — 2014-07-16

## README

## Motivation

Integration with busboy is a headache. Most existing solutions, to make things easier, save files to disk. This one keeps them in a buffer instead.

## Use

```javascript

var app = require('express')();

app.use(require('BusboyMiddleware')());

app.get('/', function(req, res) {
	res.writeHead(200, { Connection: 'close' });
	res.end('<html><head></head><body><form method="POST" enctype="multipart/form-data">\
				<input type="text" name="textfield"><br />\
				<input type="file" name="filefield"><br />\
				<input type="submit">\
			</form></body></html>');
	}
});

app.post('/', function(req, res) {
	console.log(req.body.textfield);
	console.log(req.files.filefield.name, req.files.filefield.data, req.files.filefield.mime);
});

```

## Advanced use - provide upload callback

```javascript

var app = require('express')();

app.use(require('BusboyMiddleware')(function(req, file, cb) {
	var customFilename = file.name.replace(/^[a-zA-Z0-9]/g, '') + (new Date().getTime());
	uploadToS3(customFilename, file.data, function(err, ret) {
		if (err) { cb(err); }
		else { cb(null, { name: customFilename }); }
	});
}));

app.get('/', function(req, res) {
	res.writeHead(200, { Connection: 'close' });
	res.end('<html><head></head><body><form method="POST" enctype="multipart/form-data">\
				<input type="text" name="textfield"><br />\
				<input type="file" name="filefield"><br />\
				<input type="submit">\
			</form></body></html>');
	}
});

app.post('/', function(req, res) {
	console.log(req.body.textfield);
	console.log(req.files.filefield.name); // customFilename
});

```

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