nodejs --- formidable模組 , post 上傳.

來源:互聯網
上載者:User

標籤:lower   use   cas   mit   images   ret   class   form   html   

 

 

1. 只有一個檔案域:
 1 var formidable = require(‘formidable‘), 2     http = require(‘http‘), 3     util = require(‘util‘); 4  5 http.createServer(function(req, res) { 6   if (req.url == ‘/upload‘ && req.method.toLowerCase() == ‘post‘) { 7     // parse a file upload 8     var form = new formidable.IncomingForm(); 9     form.parse(req, function(err, fields, files) {10       res.writeHead(200, {‘content-type‘: ‘text/plain‘});11       res.write(‘received upload:\n\n‘);12       res.end(util.inspect({fields: fields, files: files}));13     });14     return;15   }16 17   // show a file upload form18   res.writeHead(200, {‘content-type‘: ‘text/html‘});19   res.end(20     ‘<form action="/upload" enctype="multipart/form-data" ‘+21     ‘method="post">‘+22 23     ‘<input type="file" name="upload" multiple="multiple"><br>‘+24     ‘<input type="submit" value="Upload">‘+25     ‘</form>‘26   );27 }).listen(8888);

 

 2. 多檔案上傳:

   不可以,最後一個選擇的覆蓋住了之前的.

 

 

 

3. 兩個不同的檔案域:
 1 var formidable = require(‘formidable‘), 2     http = require(‘http‘), 3     util = require(‘util‘); 4  5 http.createServer(function(req, res) { 6   if (req.url == ‘/upload‘ && req.method.toLowerCase() == ‘post‘) { 7     // parse a file upload 8     var form = new formidable.IncomingForm(); 9     form.parse(req, function(err, fields, files) {10       res.writeHead(200, {‘content-type‘: ‘text/plain‘});11       res.write(‘received upload:\n\n‘);12       res.end(util.inspect({fields: fields, files: files}));13     });14     return;15   }16 17   // show a file upload form18   res.writeHead(200, {‘content-type‘: ‘text/html‘});19   res.end(20     ‘<form action="/upload" enctype="multipart/form-data" ‘+21     ‘method="post">‘+22 23     ‘<input type="file" name="upload01" ><br>‘+24     ‘<input type="file" name="upload02"><br>‘+25     ‘<input type="submit" value="Upload">‘+26     ‘</form>‘27   );28 }).listen(8888);

 

 

 

 

 

 

 

 

4. 除去檔案域 , 有其他的 欄位.

 

 1 var formidable = require(‘formidable‘), 2     http = require(‘http‘), 3     util = require(‘util‘); 4  5 http.createServer(function(req, res) { 6   if (req.url == ‘/upload‘ && req.method.toLowerCase() == ‘post‘) { 7     // parse a file upload 8     var form = new formidable.IncomingForm(); 9     form.parse(req, function(err, fields, files) {10       res.writeHead(200, {‘content-type‘: ‘text/plain‘});11       res.write(‘received upload:\n\n‘);12       res.end(util.inspect({fields: fields, files: files}));13     });14     return;15   }16 17   // show a file upload form18   res.writeHead(200, {‘content-type‘: ‘text/html‘});19   res.end(20     ‘<form action="/upload" enctype="multipart/form-data" ‘+21     ‘method="post">‘+22     ‘<input type="text" name="userName" ><br>‘+23     ‘<input type="password" name="password" ><br>‘+24     ‘<input type="file" name="upload01" ><br>‘+25     ‘<input type="file" name="upload02"><br>‘+26     ‘<input type="submit" value="Upload">‘+27     ‘</form>‘28   );29 }).listen(8888);

 

 

 

 

 

nodejs --- formidable模組 , post 上傳.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.