Recommend this page to a friend! |
Classes of Igor Escobar | Terminal Crossword | chat-websocket/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md | Download |
|
|
DownloadFormidablePurposeA node.js module for parsing form data, especially file uploads. Current statusThis module was developed for Transloadit, 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
Changelogv1.0.9
v1.0.8
v1.0.7
v1.0.6
v1.0.5
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
v1.0.3
v1.0.2
v1.0.1
v1.0.0
This marks the beginning of development on version 2.0 which will include several architectural improvements. v0.9.11
Important: The old property names of the File class will be removed in a future release. Older releasesThese releases were done before starting to maintain the above Changelog:
InstallationVia npm:
Manually:
Note: Formidable requires gently to run the unit tests, but you won't need it for just using the library. ExampleParse an incoming file upload.
APIformidable.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
__incomingForm.keepExtensions = false__ If you want the files written to __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 __incomingForm.hash = false__ If you want checksums calculated for incoming files, set this to either __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
__incomingForm.onPart(part)__ You may overwrite this method if you are interested in directly accessing the multipart stream. Doing so will disable any
If you want to use formidable to only handle certain parts for you, you can do so:
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. __Event: 'error' (err)__ Emitted when there is an error processing the incoming form. A request that experiences an error is automatically paused, you will have to manually call __Event: 'aborted'__ Emitted when the request was aborted by the user. Right now this can be due to a 'timeout' or 'close' event on the socket. In the future there will be a separate 'timeout' event (needs a change in the node core). __Event: 'end' ()__ Emitted when the entire request has been received, and all contained files have finished flushing to disk. This is a great place for you to send your response. formidable.File__file.size = 0__ The size of the uploaded file in bytes. If the file is still being uploaded (see __file.path = null__ The path this file is being written to. You can modify this in the __file.name = null__ The name this file had according to the uploading client. __file.type = null__ The mime type of this file, according to the uploading client. __file.lastModifiedDate = null__ A date object (or __file.hash = null__ If hash calculation was set, you can read the hex digest out of this var. LicenseFormidable is licensed under the MIT license. Ports
Credits
|