{
  "name": "multer",
  "description": "Middleware for handling `multipart/form-data`.",
  "version": "0.1.8",
  "contributors": [
    {
      "name": "Hage Yaapa",
      "email": "captain@hacksparrow.com",
      "url": "http://www.hacksparrow.com"
    },
    {
      "name": "Jaret Pfluger",
      "email": "https://github.com/jpfluger"
    }
  ],
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git://github.com/expressjs/multer"
  },
  "keywords": [
    "form",
    "post",
    "multipart",
    "form-data",
    "formdata",
    "express",
    "middleware"
  ],
  "dependencies": {
    "busboy": "~0.2.9",
    "mkdirp": "~0.3.5",
    "qs": "~1.2.2",
    "type-is": "~1.5.2"
  },
  "devDependencies": {
    "chai": "^1.9.1",
    "co": "^3.0.6",
    "express": "*",
    "mocha": "*",
    "rimraf": "^2.2.8",
    "supertest": "^0.13.0"
  },
  "engines": {
    "node": ">= 0.10.0"
  },
  "files": [
    "LICENSE",
    "index.js"
  ],
  "scripts": {
    "test": "mocha --reporter spec --bail --check-leaks"
  },
  "readme": "# 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)\n\nMulter is a node.js middleware for handling `multipart/form-data`.\n\nIt is written on top of [busboy](https://github.com/mscdex/busboy) for maximum efficiency.\n\n## API\n\n#### Installation\n\n`$ npm install multer`\n\n#### Usage\n\n```js\nvar express = require('express')\nvar multer  = require('multer')\n\nvar app = express()\napp.use(multer({ dest: './uploads/'}))\n```\n\nYou can access the fields and files in the `request` object:\n\n```js\nconsole.log(req.body)\nconsole.log(req.files)\n```\n\n**IMPORTANT**: Multer will not process any form which is not `multipart/form-data`.\n\n## Multer file object\n\nA multer file object is a JSON object with the following properties.\n\n1. `fieldname` - Field name specified in the form\n2. `originalname` - Name of the file on the user's computer\n3. `name` - Renamed file name\n4. `encoding` - Encoding type of the file\n5. `mimetype` - Mime type of the file\n6. `path` - Location of the uploaded file\n7. `extension` - Extension of the file\n8. `size` - Size of the file in bytes\n9. `truncated` - If the file was truncated due to size limitation\n10. `buffer` - Raw data (is null unless the inMemory option is true)\n\n## Options\n\nMulter accepts an options object, the most basic of which is the `dest` 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. If the `inMemory` option is true, no data is written to disk but data is kept in a buffer accessible in the file object.\n\nBy the default, Multer will rename the files so as to avoid name conflicts. The renaming function can be customized according to your needs.\n\nThe following are the options that can be passed to Multer.\n\n* `dest`\n* `limits`\n* `includeEmptyFields`\n* `inMemory`\n* `rename(fieldname, filename, req, res)`\n* `changeDest(dest, req, res)`\n* `onFileUploadStart(file, req, res)`\n* `onFileUploadData(file, data, req, res)`\n* `onFileUploadComplete(file, req, res)`\n* `onParseStart()`\n* `onParseEnd(req, next)`\n* `onError()`\n* `onFileSizeLimit(file)`\n* `onFilesLimit()`\n* `onFieldsLimit()`\n* `onPartsLimit()`\n\nApart from these, Multer also supports more advanced [busboy options](https://github.com/mscdex/busboy#busboy-methods) like `highWaterMark`, `fileHwm`, and `defCharset`.\n\nIn an average web app, only `dest` and `rename` might be required, and configured as shown in the example.\n\n```js\napp.use(multer({\n  dest: './uploads/',\n  rename: function (fieldname, filename) {\n    return filename.replace(/\\W+/g, '-').toLowerCase() + Date.now()\n  }\n}))\n```\n\nThe details of the properties of the options object is explained in the following sections.\n\n### dest\n\nThe destination directory for the uploaded files.\n\n`dest: './uploads/'`\n\n### limits\n\nAn object specifying the size limits of the following optional properties. This object is passed to busboy directly, and the details of properties can be found on [busboy's page](https://github.com/mscdex/busboy#busboy-methods)\n\n* `fieldNameSize` - integer - Max field name size (Default: 100 bytes)\n* `fieldSize` - integer - Max field value size (Default: 1MB)\n* `fields` - integer - Max number of non-file fields (Default: Infinity)\n* `fileSize` - integer - For multipart forms, the max file size (in bytes) (Default: Infinity)\n* `files` - integer - For multipart forms, the max number of file fields (Default: Infinity)\n* `parts` - integer - For multipart forms, the max number of parts (fields + files) (Default: Infinity)\n* `headerPairs` - integer - For multipart forms, the max number of header key=>value pairs to parse Default: 2000 (same as node's http).\n\n```js\nlimits: {\n  fieldNameSize: 100,\n  files: 2,\n  fields: 5\n}\n```\n\nSpecifying the limits can help protect your site against denial of service (DoS) attacks.\n\n### includeEmptyFields\n\nA Boolean value to specify whether empty submitted values should be processed and applied to `req.body`; defaults to `false`;\n\n```js\nincludeEmptyFields: true\n```\n\n### putSingleFilesInArray\n\n**NOTE** In the next major version, `putSingleFilesInArray` will go away and all `req.files` key-value pairs will point to an array of file objects. Begin migrating your code to use `putSingleFilesInArray: true`. This will become the default in the next version. An explanation follows.\n\nIn the current version `putSingleFilesInArray` is false. Activate it by setting the property to true.\n\n```js\nputSingleFilesInArray: true\n```\n\nSome applications or libraries, such as Object Modelers, expect `req.files` key-value pairs to always point to arrays. If `putSingleFilesInArray` is true, multer will ensure all values point to an array. \n\n```js\n// the value points to a single file object\nreq.files['file1'] = [fileObject1]\n// the value points to an array of file objects\nreq.files['file1'] = [fileObject1, fileObject2]\n```\n\nContrast this with Multer's default behavior, where `putSingleFilesInArray` is false. If the value for any key in `req.files` is a single file, then the value will equal a single file object. And if the value points to multiple files, then the value will equal an array of file objects.\n\n```js\n// the value points to a single file object\nreq.files['file1'] = fileObject1\n// the value points to an array of file objects\nreq.files['file1'] = [fileObject1, fileObject2]\n```\n\n### inMemory\n\nIf this Boolean value is `true`, the `file.buffer` property holds the data in-memory that Multer would have written to disk. The dest option is still populated and the path property contains the proposed path to save the file. Defaults to `false`.\n\n```js\ninMemory: true\n```\n\n**WARNING**: Uploading very large files, or relatively small files in large numbers very quickly, can cause your application to run out of memory when `inMemory` is set to `true`.\n\n### rename(fieldname, filename, req, res)\n\nFunction to rename the uploaded files. Whatever the function returns will become the new name of the uploaded file (extension is not included). The `fieldname` and `filename` of the file will be available in this function, use them if you need to.\n\n```js\nrename: function (fieldname, filename, req, res) {\n  return fieldname + filename + Date.now()\n}\n```\n\nNote that [req.body Warnings](#reqbody-warnings) applies to this function.\n\n### changeDest(dest, req, res)\n\nFunction to rename the directory in which to place uploaded files. The `dest` parameter is the default value originally assigned or passed into multer. The `req` and `res` parameters are also passed into the function because they may contain information (eg session data) needed to create the path (eg get userid from the session).\n\n```js\nchangeDest: function(dest, req, res) {\n  return dest + '/user1'; \n}\n```\n\nYou might want to check that the subdirectory has been created. Here is a synchronous way to do it. The [mkdirp](https://www.npmjs.com/package/mkdirp) module can be used to automatically create nested child directories.\n\n```js\nchangeDest: function(dest, req, res) {\n  dest += '/user1';\n  if (!fs.existsSync(dest)) fs.mkdirSync(dest);\n  return dest;  \n}\n```\n\nNote that [req.body Warnings](#reqbody-warnings) applies to this function.\n\n### onFileUploadStart(file, req, res)\n\nEvent handler triggered when a file starts to be uploaded. A file object, with the following properties, is available to this function: `fieldname`, `originalname`, `name`, `encoding`, `mimetype`, `path`, and `extension`.\n\n```js\nonFileUploadStart: function (file, req, res) {\n  console.log(file.fieldname + ' is starting ...')\n}\n```\n\nYou can even stop a file from being uploaded - just return `false` from the event handler. The file won't be processed or reach the file system.\n\n```js\nonFileUploadStart: function (file, req, res) {\n  if (file.originalname == 'virus.exe') return false;\n}\n```\n\nNote that [req.body Warnings](#reqbody-warnings) applies to this function.\n\n### onFileUploadData(file, data, req, res)\n\nEvent handler triggered when a chunk of buffer is received. A buffer object along with a file object is available to the function.\n\n```js\nonFileUploadData: function (file, data, req, res) {\n  console.log(data.length + ' of ' + file.fieldname + ' arrived')\n}\n```\n\nNote that [req.body Warnings](#reqbody-warnings) applies to this function.\n\n### onFileUploadComplete(file, req, res)\n\nEvent handler trigger when a file is completely uploaded. A file object is available to the function.\n\n```js\nonFileUploadComplete: function (file, req, res) {\n  console.log(file.fieldname + ' uploaded to  ' + file.path)\n}\n```\n\nNote that [req.body Warnings](#reqbody-warnings) applies to this function.\n\n### onParseStart()\n\nEvent handler triggered when the form parsing starts.\n\n```js\nonParseStart: function () {\n  console.log('Form parsing started at: ', new Date())\n}\n```\n\n### onParseEnd(req, next)\n\nEvent handler triggered when the form parsing completes. The `request` object and the `next` objects are are passed to the function.\n\n```js\nonParseEnd: function (req, next) {\n  console.log('Form parsing completed at: ', new Date());\n\n  // usage example: custom body parse\n  req.body = require('qs').parse(req.body);\n\n  // call the next middleware\n  next();\n}\n```\n\n**Note**: If you have created a `onParseEnd` event listener, you must manually call the `next()` function, else the request will be left hanging.\n\n### onError()\n\nEvent handler for any errors encountering while processing the form. The `error` object and the `next` object is available to the function. If you are handling errors yourself, make sure to terminate the request or call the `next()` function, else the request will be left hanging.\n\n```js\nonError: function (error, next) {\n  console.log(error)\n  next(error)\n}\n```\n\n### onFileSizeLimit()\n\nEvent handler triggered when a file size exceeds the specification in the `limit` object. No more files will be parsed after the limit is reached.\n\n```js\nonFileSizeLimit: function (file) {\n  console.log('Failed: ', file.originalname)\n  fs.unlink('./' + file.path) // delete the partially written file\n}\n```\n\n### onFilesLimit()\n\nEvent handler triggered when the number of files exceed the specification in the `limit` object. No more files will be parsed after the limit is reached.\n\n```js\nonFilesLimit: function () {\n  console.log('Crossed file limit!')\n}\n```\n\n### onFieldsLimit()\n\nEvent handler triggered when the number of fields exceed the specification in the `limit` object. No more fields will be parsed after the limit is reached.\n\n```js\nonFieldsLimit: function () {\n  console.log('Crossed fields limit!')\n}\n```\n\n### onPartsLimit()\n\nEvent handler triggered when the number of parts exceed the specification in the `limit` object. No more files or fields will be parsed after the limit is reached.\n\n```js\nonPartsLimit: function () {\n  console.log('Crossed parts limit!')\n}\n```\n\n## req.body Warnings\n\n**WARNING**: `req.body` is fully parsed after file uploads have finished. Accessing `req.body` prematurely may cause errors. The `req` and `res` parameters are added to some functions to allow the developer to access properties other than `req.body`, such as session variables or socket.io objects. You have been forwarned! :)\n\n## [MIT Licensed](LICENSE)\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/expressjs/multer/issues"
  },
  "homepage": "https://github.com/expressjs/multer",
  "_id": "multer@0.1.8",
  "dist": {
    "shasum": "d095c77b76d2907596870762440cf7c792750eb8"
  },
  "_from": "multer@",
  "_resolved": "https://registry.npmjs.org/multer/-/multer-0.1.8.tgz"
}
