Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

busboymiddleware

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

busboymiddleware

Provide a simple middleware for file uploads, using busboy.

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Weekly downloads
 
Created
Source

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


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


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
});

Keywords

FAQs

Package last updated on 10 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc