New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-form-post

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-form-post

Simple, reliable express http file and post body handler.

  • 1.0.16
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-77.78%
Maintainers
1
Weekly downloads
 
Created
Source

Express Form Post npm version js-standard-style

A simple solution to handling file and form submissions
Note: this is not recommended for use by applications that handle large files or receives a large volume of file upload requests. This is a quick solution to any application that handle small to medium sized files intended to be an abstraction for applications whose core doesn't come from file uploading.

Installation

$ npm install express-form-post --save

Usage

The information for the file uploaded will be available in the files and body object in the request object. express-form-post can be dropped in as middleware or used as a function to handle file upload. Check out the samples on the github repository for more specific usage!

Quick Start

var express = require("express");
var app = express();
var efp = require("express-form-post");
var formPost = efp();

app.use(formPost.middleware());

Disk Storage

var express = require("express");
var app = express();
var efp = require("express-form-post");
const formPost = efp({
	store: "disk",
	directory: path.join(__dirname, "tmp"),
	maxfileSize: 10000,
	filename: function(originalname, fieldname, mimetype) {
		return Date.now() + "-" + originalname;
	},
	validate: function(fieldname, originalname, mimetype) {
		console.log(mimetype);
		if(mimetype != "application/pdf") {
			return false;
		}
	}
});

app.use(formPost.middleware(function(err) {
	if(err) console.log(err);
	console.log("Here are my files:", req.files);
}));

Usage with aws-s3

$ npm install aws-sdk --save
var express = require("express");
var app = express();
var efp = require("express-form-post");
const formPost = efp({
	store: "aws-s3",
	maxfileSize: 100000,
	filename: function(originalname, fieldname, mimetype) {
		return originalname;
	},
	api: {
		accessKeyId: process.env.AWS_ACCESS_KEY_ID,
		secretAccessKey: process.env.secretAccessKey,
		bucketName: process.env.S3_BUCKET_NAME,
		ACL: "public-read"
	}
})

app.use(formPost.middleware(function(err) {
	if(err) console.log(err);
	console.log("Here are my files", req.files);
}));

Usage with dropbox

$ npm install dropbox --save
var express = require("express");
var app = express();
var efp = require("express-form-post");
const formPost = efp({
	store: "dropbox",
	filename: function(originalname, fieldname, mimetype) {
		return originalname;
	},
	api: {
		accessToken: process.env.dropboxAccessToken
	}
});

app.use(formPost.middleware(function(err) {
	if(err) console.log(err);
	console.log("Here are my files", req.files);
}));

Usage as an asynchronous function

app.post("*", (req, res, next) => { 
	formPost.upload(req, res, (err) => {
		if(err) {
			console.log(err);
		}
		console.log("My files are located here:", req.files);
		res.redirect("/");
	});
}

express-form-post API

When initializing an instance of efp (express-form-post) you can provide it different options that will change the way efp handles your file uploads.

express-form-post(opts)

express-form-post accepts an "optional" options parameter list. Keep in mind all fields are OPTIONAL. If you don't provide any, the express-form-post api will take care of that using the default options.

KeyDescriptionNote
storeThe type of storecheck below for available store methods
directoryThe folder to which the file will be saveddefaults to current directory
filenamefunction to determine file save namedefaults to the file's name on the user's computer
maxfileSizeMaximum Size of the uploaded file in bytesdefaults to infiniti
minfileSizeMinimum Size of the uploaded file in bytesdefaults to 0
validatefunction to validate uploaded file
apiapi configuration information (api keys)read further documentation for specifications

Available storage methods

  • disk storage
  • aws s3
  • dropbox

Configuring API storage

Here are the different information you can input for each api storage. These options would go inside the api property of the options listed above.

aws-s3
KeyDescriptionNote
accessKeyIdAWS access key idThis is required. You can find it here : aws console
secretAccessKeysecret key for awsOptional based on your s3 settings
bucketNameThe name of your bucket.This is required.
ACLAccess control listPrivacy control. Defaults to "private"
dropbox
KeyDescriptionNote
accessTokenused by Dropbox to identify your appThis is required. Check out the docs
clientIdDropbox client IdOptional
selectUserSpecific user in a team boxOptional

Keywords

FAQs

Package last updated on 19 Jun 2017

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