package.json
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"_args": [
[
{
"raw": "multiparty",
"scope": null,
"escapedName": "multiparty",
"name": "multiparty",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"/Users/fzy/project/koa2_Sequelize_project"
]
],
"_from": "multiparty@latest",
"_id": "multiparty@4.1.3",
"_inCache": true,
"_location": "/multiparty",
"_nodeVersion": "4.6.1",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/multiparty-4.1.3.tgz_1485120038647_0.7718258867971599"
},
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"_npmVersion": "2.15.9",
"_phantomChildren": {},
"_requested": {
"raw": "multiparty",
"scope": null,
"escapedName": "multiparty",
"name": "multiparty",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_resolved": "https://registry.npmjs.org/multiparty/-/multiparty-4.1.3.tgz",
"_shasum": "3c43c7fcb1896e17460436a9dd0b6ef1668e4f94",
"_shrinkwrap": null,
"_spec": "multiparty",
"_where": "/Users/fzy/project/koa2_Sequelize_project",
"author": {
"name": "Andrew Kelley",
"email": "superjoe30@gmail.com"
},
"bugs": {
"url": "https://github.com/pillarjs/multiparty/issues"
},
"dependencies": {
"fd-slicer": "~1.0.1"
},
"description": "multipart/form-data parser which supports streaming",
"devDependencies": {
"findit2": "~2.2.3",
"istanbul": "~0.4.3",
"mkdirp": "~0.5.1",
"pend": "~1.2.0",
"rimraf": "~2.5.2",
"superagent": "~0.21.0"
},
"directories": {
"example": "examples",
"test": "test"
},
"dist": {
"shasum": "3c43c7fcb1896e17460436a9dd0b6ef1668e4f94",
"tarball": "https://registry.npmjs.org/multiparty/-/multiparty-4.1.3.tgz"
},
"engines": {
"node": ">=0.10.0"
},
"gitHead": "dcbd3d6390535e09fd09f6d26c4928942df31bb1",
"homepage": "https://github.com/pillarjs/multiparty#readme",
"keywords": [
"file",
"upload",
"formidable",
"stream",
"s3"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "superjoe",
"email": "superjoe30@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"name": "multiparty",
"optionalDependencies": {},
"readme": "# multiparty [](https://travis-ci.org/pillarjs/multiparty) [](https://coveralls.io/r/pillarjs/multiparty)\n\nParse http requests with content-type `multipart/form-data`, also known as file uploads.\n\nSee also [busboy](https://github.com/mscdex/busboy) - a\n[faster](https://github.com/mscdex/dicer/wiki/Benchmarks) alternative\nwhich may be worth looking into.\n\n### Why the fork?\n\n * This module uses the Node.js v0.10 streams properly\n * It will not create a temp file for you unless you want it to.\n * Counts bytes and does math to help you figure out the `Content-Length` of\n the final part.\n * You can stream uploads to s3 with\n [aws-sdk](https://github.com/aws/aws-sdk-js), for [example](examples/s3.js).\n * Less bugs. This code is simpler, has all deprecated functionality removed,\n has cleaner tests, and does not try to do anything beyond multipart stream\n parsing.\n\n## Installation\n\n```\nnpm install multiparty\n```\n\n## Usage\n\n * See [examples](examples).\n\nParse an incoming `multipart/form-data` request.\n\n```js\nvar multiparty = require('multiparty');\nvar http = require('http');\nvar util = require('util');\n\nhttp.createServer(function(req, res) {\n if (req.url === '/upload' && req.method === 'POST') {\n // parse a file upload\n var form = new multiparty.Form();\n\n form.parse(req, function(err, fields, files) {\n res.writeHead(200, {'content-type': 'text/plain'});\n res.write('received upload:\\n\\n');\n res.end(util.inspect({fields: fields, files: files}));\n });\n\n return;\n }\n\n // show a file upload form\n res.writeHead(200, {'content-type': 'text/html'});\n res.end(\n '<form action=\"/upload\" enctype=\"multipart/form-data\" method=\"post\">'+\n '<input type=\"text\" name=\"title\"><br>'+\n '<input type=\"file\" name=\"upload\" multiple=\"multiple\"><br>'+\n '<input type=\"submit\" value=\"Upload\">'+\n '</form>'\n );\n}).listen(8080);\n```\n\n## API\n\n### multiparty.Form\n\n```js\nvar form = new multiparty.Form(options)\n```\n\nCreates a new form. Options:\n\n * `encoding` - sets encoding for the incoming form fields. Defaults to `utf8`.\n * `maxFieldsSize` - Limits the amount of memory all fields (not files) can\n allocate in bytes. If this value is exceeded, an `error` event is emitted.\n The default size is 2MB.\n * `maxFields` - Limits the number of fields that will be parsed before\n emitting an `error` event. A file counts as a field in this case.\n Defaults to 1000.\n * `maxFilesSize` - Only relevant when `autoFiles` is `true`. Limits the\n total bytes accepted for all files combined. If this value is exceeded,\n an `error` event is emitted. The default is `Infinity`.\n * `autoFields` - Enables `field` events and disables `part` events for fields.\n This is automatically set to `true` if you add a `field` listener.\n * `autoFiles` - Enables `file` events and disables `part` events for files.\n This is automatically set to `true` if you add a `file` listener.\n * `uploadDir` - Only relevant when `autoFiles` is `true`. The directory for\n placing file uploads in. You can move them later using `fs.rename()`.\n Defaults to `os.tmpdir()`.\n\n#### form.parse(request, [cb])\n\nParses an incoming node.js `request` containing form data.This will cause\n`form` to emit events based off the incoming request.\n\n```js\nvar count = 0;\nvar form = new multiparty.Form();\n\n// Errors may be emitted\n// Note that if you are listening to 'part' events, the same error may be\n// emitted from the `form` and the `part`.\nform.on('error', function(err) {\n console.log('Error parsing form: ' + err.stack);\n});\n\n// Parts are emitted when parsing the form\nform.on('part', function(part) {\n // You *must* act on the part by reading it\n // NOTE: if you want to ignore it, just call \"part.resume()\"\n\n if (!part.filename) {\n // filename is not defined when this is a field and not a file\n console.log('got field named ' + part.name);\n // ignore field's content\n part.resume();\n }\n\n if (part.filename) {\n // filename is defined when this is a file\n count++;\n console.log('got file named ' + part.name);\n // ignore file's content here\n part.resume();\n }\n\n part.on('error', function(err) {\n // decide what to do\n });\n});\n\n// Close emitted after form parsed\nform.on('close', function() {\n console.log('Upload completed!');\n res.setHeader('text/plain');\n res.end('Received ' + count + ' files');\n});\n\n// Parse req\nform.parse(req);\n```\n\nIf `cb` is provided, `autoFields` and `autoFiles` are set to `true` and all\nfields and files are collected and passed to the callback, removing the need to\nlisten to any events on `form`. This is for convenience when you want to read\neverything, but be sure to write cleanup code, as this will write all uploaded\nfiles to the disk, even ones you may not be interested in.\n\n```js\nform.parse(req, function(err, fields, files) {\n Object.keys(fields).forEach(function(name) {\n console.log('got field named ' + name);\n });\n\n Object.keys(files).forEach(function(name) {\n console.log('got file named ' + name);\n });\n\n console.log('Upload completed!');\n res.setHeader('text/plain');\n res.end('Received ' + files.length + ' files');\n});\n```\n\n`fields` is an object where the property names are field names and the values\nare arrays of field values.\n\n`files` is an object where the property names are field names and the values\nare arrays of file objects.\n\n#### form.bytesReceived\n\nThe amount of bytes received for this form so far.\n\n#### form.bytesExpected\n\nThe expected number of bytes in this form.\n\n### Events\n\n#### 'error' (err)\n\nUnless you supply a callback to `form.parse`, you definitely want to handle\nthis event. Otherwise your server *will* crash when users submit bogus\nmultipart requests!\n\nOnly one 'error' event can ever be emitted, and if an 'error' event is\nemitted, then 'close' will not be emitted.\n\nIf the error would correspond to a certain HTTP response code, the `err` object\nwill have a `statusCode` property with the value of the suggested HTTP response\ncode to send back.\n\nNote that an 'error' event will be emitted both from the `form` and from the\ncurrent `part`.\n\n#### 'part' (part)\n\nEmitted when a part is encountered in the request. `part` is a\n`ReadableStream`. It also has the following properties:\n\n * `headers` - the headers for this part. For example, you may be interested\n in `content-type`.\n * `name` - the field name for this part\n * `filename` - only if the part is an incoming file\n * `byteOffset` - the byte offset of this part in the request body\n * `byteCount` - assuming that this is the last part in the request,\n this is the size of this part in bytes. You could use this, for\n example, to set the `Content-Length` header if uploading to S3.\n If the part had a `Content-Length` header then that value is used\n here instead.\n\nParts for fields are not emitted when `autoFields` is on, and likewise parts\nfor files are not emitted when `autoFiles` is on.\n\n`part` emits 'error' events! Make sure you handle them.\n\n#### 'aborted'\n\nEmitted when the request is aborted. This event will be followed shortly\nby an `error` event. In practice you do not need to handle this event.\n\n#### 'progress' (bytesReceived, bytesExpected)\n\n#### 'close'\n\nEmitted after all parts have been parsed and emitted. Not emitted if an `error`\nevent is emitted.\n\nIf you have `autoFiles` on, this is not fired until all the data has been\nflushed to disk and the file handles have been closed.\n\nThis is typically when you would send your response.\n\n#### 'file' (name, file)\n\n**By default multiparty will not touch your hard drive.** But if you add this\nlistener, multiparty automatically sets `form.autoFiles` to `true` and will\nstream uploads to disk for you. \n\n**The max bytes accepted per request can be specified with `maxFilesSize`.**\n\n * `name` - the field name for this file\n * `file` - an object with these properties:\n - `fieldName` - same as `name` - the field name for this file\n - `originalFilename` - the filename that the user reports for the file\n - `path` - the absolute path of the uploaded file on disk\n - `headers` - the HTTP headers that were sent along with this file\n - `size` - size of the file in bytes\n\n#### 'field' (name, value)\n\n * `name` - field name\n * `value` - string field value\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/pillarjs/multiparty.git"
},
"scripts": {
"test": "node test/test.js",
"test-cov": "istanbul cover test/test.js",
"test-travis": "istanbul cover test/test.js --report lcovonly"
},
"version": "4.1.3"
}