Comparing version 1.0.1 to 1.0.2
@@ -101,2 +101,3 @@ var is = require('type-is') | ||
var aborting = false | ||
pendingWrites.increment() | ||
@@ -116,3 +117,3 @@ | ||
fileStream.on('limit', function () { | ||
pendingWrites.decrement() | ||
aborting = true | ||
abortWithCode('LIMIT_FILE_SIZE', fieldname) | ||
@@ -122,2 +123,7 @@ }) | ||
storage._handleFile(req, file, function (err, info) { | ||
if (aborting) { | ||
uploadedFiles.push(extend(file, info)) | ||
return pendingWrites.decrement() | ||
} | ||
if (err) { | ||
@@ -124,0 +130,0 @@ pendingWrites.decrement() |
{ | ||
"name": "multer", | ||
"description": "Middleware for handling `multipart/form-data`.", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"contributors": [ | ||
@@ -30,2 +30,3 @@ "Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)", | ||
"devDependencies": { | ||
"express": "^4.13.1", | ||
"form-data": "^1.0.0-rc1", | ||
@@ -32,0 +33,0 @@ "fs-temp": "^0.1.2", |
# Multer [![Build Status](https://travis-ci.org/expressjs/multer.svg?branch=master)](https://travis-ci.org/expressjs/multer) [![NPM version](https://badge.fury.io/js/multer.svg)](https://badge.fury.io/js/multer) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
Multer is a node.js middleware for handling `multipart/form-data`. It is written | ||
Multer is a node.js middleware for handling `multipart/form-data`, which is primarily used for uploading files. It is written | ||
on top of [busboy](https://github.com/mscdex/busboy) for maximum efficiency. | ||
**NOTE**: Multer will not process any form which is not multipart (`multipart/form-data`). | ||
## Installation | ||
```sh | ||
npm install --save multer | ||
$ npm install --save multer | ||
``` | ||
@@ -14,2 +16,6 @@ | ||
Multer adds a `body` object and a `file` or `files` object to the `request` object. The `body` object contains the values of the text fields of the form, the `file` or `files` object contains the files uploaded via the form. | ||
Basic usage example: | ||
```javascript | ||
@@ -24,2 +30,3 @@ var express = require('express') | ||
// req.file is the `avatar` file | ||
// req.body will hold the text fields, if there were any | ||
}) | ||
@@ -29,2 +36,3 @@ | ||
// req.files is array of `photos` files | ||
// req.body will contain the text fields, if there were any | ||
}) | ||
@@ -39,13 +47,20 @@ | ||
// req.files['gallery'] -> Array | ||
// | ||
// req.body will contain the text fields, if there were any | ||
}) | ||
``` | ||
You can access post data fields as `body` on the `request` object: | ||
In case you need to handle a text-only multipart form, you can use any of the multer methods (`.single()`, `.array()`, `fields()`). Here is an example using `.array()`: | ||
```javascript | ||
console.log(req.body) | ||
var express = require('express') | ||
var app = express() | ||
var multer = require('multer') | ||
var upload = multer() | ||
app.post('/profile', upload.array(), function (req, res, next) { | ||
// req.body contains the text fields | ||
}) | ||
``` | ||
**IMPORTANT**: Multer will only process forms which are of the type `multipart/form-data`. | ||
## API | ||
@@ -73,4 +88,3 @@ | ||
property, which tells Multer where to upload the files. In case you omit the | ||
options object, the file will be renamed and uploaded to the temporary directory | ||
of the system. | ||
options object, the files will be kept in memory and never written to disk. | ||
@@ -92,3 +106,3 @@ By default, Multer will rename the files so as to avoid naming conflicts. The | ||
```javascript | ||
app.use(multer({ dest: 'uploads/' })) | ||
var upload = multer({ dest: 'uploads/' }) | ||
``` | ||
@@ -142,3 +156,3 @@ | ||
app.use(multer({ storage: storage })) | ||
var upload = multer({ storage: storage }) | ||
``` | ||
@@ -150,6 +164,17 @@ | ||
`destination` is used to determine within which folder the uploaded files should | ||
be stored. This can also be given as a `string` (e.g. `'/tmp/uploads'`). | ||
be stored. This can also be given as a `string` (e.g. `'/tmp/uploads'`). If no | ||
`destination` is given, the operating system's default directory for temporary | ||
files is used. | ||
**Note:** You are responsible for creating the directory when providing | ||
`destination` as a function. When passing a string, multer will make sure that | ||
the directory is created for you. | ||
`filename` is used to determine what the file should be named inside the folder. | ||
If no `filename` is given, each file will be given a random name that doesn't | ||
include any file extension. | ||
**Note:** Multer will not append any file extension for you, your function | ||
should return a filename complete with an file extension. | ||
Each function gets passed both the request (`req`) and some information about | ||
@@ -168,4 +193,3 @@ the file (`file`) to aid with the decision. | ||
var storage = multer.memoryStorage() | ||
app.use(multer({ storage: storage })) | ||
var upload = multer({ storage: storage }) | ||
``` | ||
@@ -172,0 +196,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21871
326
267
7