Nodejs---Formidable module, post upload.

Source: Internet
Author: User

1. There is only one file field:
1 varFormidable = require (' formidable ')),2HTTP = require (' http '),3Util = require (' util '));4 5Http.createserver (function(req, res) {6   if(Req.url = = '/upload ' && req.method.toLowerCase () = = ' Post ') {7     //parse a file upload8     varform =NewFormidable. Incomingform ();9Form.parse (req,function(Err, fields, files) {TenRes.writehead, {' Content-type ': ' Text/plain '}); OneRes.write (' Received upload:\n\n '); A Res.end (Util.inspect ({fields:fields, files:files})); -     }); -     return; the   } -  -   //show a file upload form -Res.writehead, {' Content-type ': ' text/html '}); + Res.end ( -' <form action= '/upload "enctype=" multipart/form-data "' + +' method= ' post > ' + A  at' <input type= ' file ' name= ' upload ' multiple= ' multiple ' ><br> ' + -' <input type= ' submit ' value= ' Upload ' > ' + -' </form> ' -   ); -}). Listen (8888);

2. Multiple file uploads:

No, the last selection covers the previous one.

3. Two different file domains:
1 varFormidable = require (' formidable ')),2HTTP = require (' http '),3Util = require (' util '));4 5Http.createserver (function(req, res) {6   if(Req.url = = '/upload ' && req.method.toLowerCase () = = ' Post ') {7     //parse a file upload8     varform =NewFormidable. Incomingform ();9Form.parse (req,function(Err, fields, files) {TenRes.writehead, {' Content-type ': ' Text/plain '}); OneRes.write (' Received upload:\n\n '); A Res.end (Util.inspect ({fields:fields, files:files})); -     }); -     return; the   } -  -   //show a file upload form -Res.writehead, {' Content-type ': ' text/html '}); + Res.end ( -' <form action= '/upload "enctype=" multipart/form-data "' + +' method= ' post > ' + A  at' <input type= ' file 'name= "UPLOAD01"><br> ' + -' <input type= ' file 'name= "UPLOAD02"><br> ' + -' <input type= ' submit ' value= ' Upload ' > ' + -' </form> ' -   ); -}). Listen (8888);

4. Remove the file field, there are other fields.

1 varFormidable = require (' formidable ')),2HTTP = require (' http '),3Util = require (' util '));4 5Http.createserver (function(req, res) {6   if(Req.url = = '/upload ' && req.method.toLowerCase () = = ' Post ') {7     //parse a file upload8     varform =NewFormidable. Incomingform ();9Form.parse (req,function(Err, fields, files) {TenRes.writehead, {' Content-type ': ' Text/plain '}); OneRes.write (' Received upload:\n\n '); A Res.end (Util.inspect ({fields:fields, files:files})); -     }); -     return; the   } -  -   //show a file upload form -Res.writehead, {' Content-type ': ' text/html '}); + Res.end ( -' <form action= '/upload "enctype=" multipart/form-data "' + +' method= ' post > ' + A' <input type= ' text 'name= "UserName"><br> ' + at' <input type= ' password 'name= "Password"><br> ' + -' <input type= ' file 'name= "UPLOAD01"><br> ' + -' <input type= ' file 'name= "UPLOAD02"><br> ' + -' <input type= ' submit ' value= ' Upload ' > ' + -' </form> ' -   ); in}). Listen (8888);

Nodejs---Formidable module, post upload.

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.