# Formidable
## Purpose
A node.js module for parsing form data, especially file uploads.
## Current status
This module was developed for [Transloadit](http://transloadit.com/), a service focused on uploading
and encoding images and videos. It has been battle-tested against hundreds of GB of file uploads from
a large variety of clients and is considered production-ready.
## Features
* Fast (~500mb/sec), non-buffering multipart parser
* Automatically writing file uploads to disk
* Low memory footprint
* Graceful error handling
* Very high test coverage
## Changelog
### v1.0.6
* Do not default to the default to the field name for file uploads where
filename="".
### v1.0.5
* Support filename="" in multipart parts
* Explain unexpected end() errors in parser better
**Note:** Starting with this version, formidable emits 'file' events for empty
file input fields. Previously those were incorrectly emitted as regular file
input fields with value = "".
### v1.0.4
* Detect a good default tmp directory regardless of platform. (#88)
### v1.0.3
* Fix problems with utf8 characters (#84) / semicolons in filenames (#58)
* Small performance improvements
* New test suite and fixture system
### v1.0.2
* Exclude node\_modules folder from git
* Implement new `'aborted'` event
* Fix files in example folder to work with recent node versions
* Make gently a devDependency
[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.1...v1.0.2)
### v1.0.1
* Fix package.json to refer to proper main directory. (#68, Dean Landolt)
[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.0...v1.0.1)
### v1.0.0
* Add support for multipart boundaries that are quoted strings. (Jeff Craig)
This marks the beginning of development on version 2.0 which will include
several architectural improvements.
[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.11...v1.0.0)
### v0.9.11
* Emit `'progress'` event when receiving data, regardless of parsing it. (Tim Koschützki)
* Use [W3C FileAPI Draft](http://dev.w3.org/2006/webapi/FileAPI/) properties for File class
**Important:** The old property names of the File class will be removed in a
future release.
[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.10...v0.9.11)
### Older releases
These releases were done before starting to maintain the above Changelog:
* [v0.9.10](https://github.com/felixge/node-formidable/compare/v0.9.9...v0.9.10)
* [v0.9.9](https://github.com/felixge/node-formidable/compare/v0.9.8...v0.9.9)
* [v0.9.8](https://github.com/felixge/node-formidable/compare/v0.9.7...v0.9.8)
* [v0.9.7](https://github.com/felixge/node-formidable/compare/v0.9.6...v0.9.7)
* [v0.9.6](https://github.com/felixge/node-formidable/compare/v0.9.5...v0.9.6)
* [v0.9.5](https://github.com/felixge/node-formidable/compare/v0.9.4...v0.9.5)
* [v0.9.4](https://github.com/felixge/node-formidable/compare/v0.9.3...v0.9.4)
* [v0.9.3](https://github.com/felixge/node-formidable/compare/v0.9.2...v0.9.3)
* [v0.9.2](https://github.com/felixge/node-formidable/compare/v0.9.1...v0.9.2)
* [v0.9.1](https://github.com/felixge/node-formidable/compare/v0.9.0...v0.9.1)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0)
## Installation
Via [npm](http://github.com/isaacs/npm):
npm install formidable@latest
Manually:
git clone git://github.com/felixge/node-formidable.git formidable
vim my.js
# var formidable = require('./formidable');
Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run the unit tests, but you won't need it for just using the library.
## Example
Parse an incoming file upload.
var formidable = require('formidable'),
http = require('http'),
sys = require('sys');
http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(sys.inspect({fields: fields, files: files}));
});
return;
}
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(80);
## API
### formidable.IncomingForm
#### new formidable.IncomingForm()
Creates a new incoming form.
#### incomingForm.encoding = 'utf-8'
The encoding to use for incoming form fields.
#### incomingForm.uploadDir = process.env.TMP || '/tmp' || process.cwd()
The directory for placing file uploads in. You can move them later on using
`fs.rename()`. The default directory is picked at module load time depending on
the first existing directory from those listed above.
#### incomingForm.keepExtensions = false
If you want the files written to `incomingForm.uploadDir` to include the extensions of the original files, set this property to `true`.
#### incomingForm.type
Either 'multipart' or 'urlencoded' depending on the incoming request.
#### incomingForm.maxFieldsSize = 2 * 1024 * 1024
Limits the amount of memory a field (not file) can allocate in bytes.
If this value is exceeded, an `'error'` event is emitted. The default
size is 2MB.
#### incomingForm.bytesReceived
The amount of bytes received for this form so far.
#### incomingForm.bytesExpected
The expected number of bytes in this form.
#### incomingForm.parse(request, [cb])
Parses an incoming node.js `request` containing form data. If `cb` is provided, all fields an files are collected and passed to the callback:
incomingForm.parse(req, function(err, fields, files) {
// ...
});
#### incomingForm.onPart(part)
You may overwrite this method if you are interested in directly accessing the multipart stream. Doing so will disable any `'field'` / `'file'` events processing which would occur otherwise, making you fully responsible for handling the processing.
incomingForm.onPart = function(part) {
part.addListener('data', function() {
// ...
});
}
If you want to use formidable to only handle certain parts for you, you can do so:
incomingForm.onPart = function(part) {
if (!part.filename) {
// let formidable handle all non-file parts
incomingForm.handlePart(part);
}
}
Check the code in this method for further inspiration.
#### Event: 'progress' (bytesReceived, bytesExpected)
Emitted after each incoming chunk of data that has been parsed. Can be used to roll your own progress bar.
#### Event: 'field' (name, value)
Emitted whenever a field / value pair has been received.
#### Event: 'fileBegin' (name, file)
Emitted whenever a new file is detected in the upload stream. Use this even if
you want to stream the file to somewhere else while buffering the upload on
the file system.
#### Event: 'file' (name, file)
Emitted whenever a field / file pair has been received. `file` is an instance of `File`.
#### Event: 'error' (err)
Em
没有合适的资源?快使用搜索试试~ 我知道了~
HTML5 in Action 源码
共574个文件
js:227个
png:159个
html:49个
5星 · 超过95%的资源 需积分: 9 106 下载量 140 浏览量
2015-03-20
11:02:53
上传
评论 1
收藏 4.67MB ZIP 举报
温馨提示
作者: [英]罗伯·克洛泽(Rob Crowther),[爱]乔·列侬 HTML5并非是在旧的标准上添加的几个新标签和新特性,它是现代Web的基石,能够实现交互式服务、单页UI、交互式游戏、复杂业务应用。凭借对标准驱动的移动应用开发的支持,以及各种强大特性(如本地存储、WebSockets、优秀的音频及视频API、使用CSS3的新布局方案,乃至SVG和Canvas技术),HTML5迎来了它的黄金时代。 《HTML5实战》完整地介绍了使用HTML5技术进行Web开发的各项内容,通过真实的示例及代码探讨了HTML5规范。诚如书名所示,本书内容注重实务指导,读者通过亲自实践必定能使网站与应用达到前所未有的效果? 本书重点介绍HTML5的新特性,并假定读者熟悉标准HTML。 要下载本书代码可以访问 manning.com/HTML5inAction
资源推荐
资源详情
资源评论
收起资源包目录
HTML5 in Action 源码 (574个子文件)
tasks.appcache 73B
benchmark-native.c 613B
benchmark-native.c 613B
style.css 9KB
style.css 5KB
style.css 4KB
style.css 3KB
style.css 3KB
style.css 1KB
style.css 948B
client.css 893B
client.css 893B
style.css 759B
index.ejs 2KB
index.ejs 2KB
.gitignore 39B
.gitignore 39B
.gitignore 23B
.gitignore 23B
.gitignore 23B
.gitignore 23B
.gitignore 13B
.gitignore 13B
.gitmodules 207B
.gitmodules 207B
bench.gnu 6KB
bench.gnu 6KB
wilson-controller-fullscreen-pointerlock.html 11KB
index-10.html 9KB
wilson-controller-fullscreen-orientation-vibration-battery.html 9KB
wilson-controller-fullscreen-battery.html 9KB
wilson-controller-fullscreen-orientation-vibration.html 9KB
wilson-controller-fullscreen-orientation.html 9KB
wilson-controller-fullscreen.html 8KB
index.html 8KB
index-8.html 8KB
index-9.html 8KB
index-6-shapes.html 7KB
index-6.html 7KB
index-7.html 7KB
wilson-controller-captureevents.html 7KB
wilson-controller.html 6KB
libwebsockets-test.html 6KB
libwebsockets-test.html 6KB
index-6-events.html 4KB
wilson.html 4KB
index.html 4KB
index-5.html 4KB
index-4-ie9.html 4KB
canvas-composition-modes.html 3KB
index-3-events.html 3KB
index-4.html 3KB
fragmentation-test-page.html 3KB
fragmentation-test-page.html 3KB
index-2.html 3KB
index.html 2KB
index-3-ie9.html 2KB
index.html 2KB
index-3.html 2KB
index.html 2KB
directory.html 2KB
directory.html 2KB
index.html 1KB
index-1.html 1KB
html5-blog.html 1KB
html5-microdata.html 1KB
index-0.html 1011B
html4-blog.html 876B
websocket-sample.html 488B
login-mockup.html 469B
index.html 352B
test.html 340B
test.html 340B
hello.html 242B
error.html 238B
error.html 238B
osx-chrome-13.http 1KB
osx-chrome-13.http 1KB
osx-firefox-3.6.http 977B
osx-firefox-3.6.http 977B
xp-chrome-12.http 945B
xp-chrome-12.http 945B
osx-safari-5.http 920B
osx-safari-5.http 920B
xp-safari-5.http 881B
xp-safari-5.http 881B
xp-ie-8.http 833B
xp-ie-8.http 833B
xp-ie-7.http 820B
xp-ie-7.http 820B
generic.http 353B
generic.http 353B
favicon.ico 1KB
favicon.ico 1KB
panorama.jpg 5.39MB
background.jpg 26KB
jquery-1.7.2.min.js 93KB
jquery-1.7.1.min.js 92KB
jquery-1.8.2.min.js 91KB
ctio.js 40KB
共 574 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- 多云间晴2018-12-25很实用,谢谢分享
- 丢嘞2015-09-28大牛的源码,阅读起来很好,受益匪浅
- 法克你大野2015-07-25我老是提醒自己要做开发大牛不能看源码, 可是怎么也控制不住
- 大猫聪聪2016-02-23很有用,感谢了
- jackson_wangxd2015-07-16源码都是精华,谢谢!
loneleaf1
- 粉丝: 44
- 资源: 130
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功