Use of the formidable module for node. js

Source: Internet
Author: User

1) Create Formidable.incomingform object var form = new Formidable. Incomingform () 2) form.encoding = ' Utf-8 ' Sets the encoding of the form field 3) Form.uploaddir = "/my/dir"; Set the folder where the uploaded files are stored, by default
System temporary folder, you can use Fs.rename () to change the location of the upload file and file name 4) Form.keepextensions = false; Setting this property to True allows the uploaded file to keep the original file extension. 5) Form.type read-only, depending on the type of request, take value ' multipart ' or ' urlencoded ' 6) form.maxfieldssize = 2 * 1024 * 1024; Limit the size of all stored form fields
Small (except for the file field), if exceeded, the error event is triggered, default is 2m7) Form.maxfields = 1000 Sets how many query strings can be converted, default is 10008) Form.hash = false; Set the verification code of the uploaded file, can have two values of ' SHA1 ' or ' MD5 '. 9) Form.multiples = false;
Turn on this function, when calling the Form.parse () method, the callback function
The files parameter will be a file array, each member of the array is a file pair
This feature requires multiple feature support in HTML5. form.bytesreceived return the server has received the current form data how many bytes each) form.bytesexpected returns the size of all data that will be received for the current form. Form.parse (Request, [Callbac K])
The method transforms the form data contained in the request and callback
Contains all field fields and file information, such as: form.parse (req, Function (Err, fields, files) {//...}); Form.onpart (part); You can overload the method of handling the multipart stream, and doing so will prohibit field and
File event occurs, you will have to handle these things yourself, such as: Form.onpart = function (part) {Part.addlistener (' data ', function () {   ...      }); If you want formdable to handle only a subset of things, you can do this: Form.onpart = function (part) {if (!part.filename) {//Let formidable      All non-document parts Form.handlepart (part); }}14) formidable. File Object A. File.size = 0
The size of the uploaded file, if the file is being uploaded, represents the size of the uploaded part B. File.path = null
The path to the uploaded file. If you don't want formidable to produce a temporary
folder, you can modify the path C in the Filebegain event. File.name = NULL The name of the upload file D. File.type = NULL The MIME type of the upload file E. File.lastmodifieddate = null Time object, the last time the file was modified F. File.hash = NULL Returns the hash value of the file G. You can use Json.stringify (File.tojson ()) to format the output file information (Form.on) (' Progress ', function (bytesreceived, bytesexpected) {});
This event is triggered when a block of data is processed and is useful for creating a progress bar. Form.on (' field ', function (name, value) {});
This event is triggered whenever a field/value pair has been received) Form.on (' Filebegin ', function (name, file) {});
Any new file detected in the post stream will trigger the event Form.on (' file ', function (name, file) {});
Each time a pair of fields/files have been received, the event is triggered by Form.on (' Error ', function (err) {});
This event is triggered when an error occurs in the upload stream, and when an error occurs, if you want to continue triggering the request
Data event, you must manually call the Request.resume () method) Form.on (' aborted ', function () {});
This event is triggered when the user aborts the request, and the timeout and close events in the socket also trigger the
Form.on (' End ', function () {}), when the event is triggered, the error event will also be triggered.
When all the requests have been received and all the files have been uploaded to the server,
The event is triggered. The request can now be sent to the client. Note: This article is translated from https://www.npmjs.com/package/formidable

  

Use of the formidable module for node. js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.