Node(20) File Upload with formidable module
来源:互联网 发布:java sleep1000 编辑:程序博客网 时间:2024/04/20 00:37
handling file upload needs to include formidable module, writing raw code for file upload is tough.
var http = require('http');var formidable = require('formidable');var form = require('fs').readFileSync('form.html');http.createServer( function(request, response){//handle post filesif( request.method === 'POST' ){//create a formidable incomingFormvar incoming = new formidable.IncomingForm();//upload to uploads folderincoming.uploadDir = 'uploads';//listen to file eventincoming.on('fileBegin', function(field,file){//appended the origin filename at the end after random filenameif( file.name ){file.path += "_" + file.name}}).on( 'file', function( field, file ){if( !file.size){return;}response.write( file.name + ' received\n');}).on( 'end', function(){response.end( 'All files received');}).on( 'field', function( field, value ){response.write( field + ' - ' + value + '\n');});incoming.parse(request );}//handle get if (request.method === "GET") { response.writeHead(200, { 'Content-Type': 'text/html' }); response.end(form); }}).listen(9000);
note: formidable can also handle POST data using 'field' event
Reference
- Node(20) File Upload with formidable module
- File Upload with ASP.NET
- Secure File Upload with PHP
- Html5 File Upload with Progress
- Image / file upload with CodeIgniter
- node-formidable详解
- node-formidable详解
- node.js模块--formidable
- node.js+formidable
- node开发之Formidable
- node js Formidable中间件
- Node.js文件上传的时候控制台报Error: Cannot find module 'formidable'
- ASP.NET File Upload with Progress Bar
- Node.js的formidable模块
- use curl to upload file with remote php file
- 自学Node.js 五:学习node-formidable
- upload file
- Upload file
- 基础2012.8.2.00.00
- 8583报文手工拆解
- 基础2012.8.3.00.00
- 基础2012.8.4.00.00
- struts2session与request的值问题
- Node(20) File Upload with formidable module
- JS表单验证Email地址
- 汇编语言写引导扇区
- 39个让你受益的HTML5教程
- extjs4.0——charts
- 杭电acm1032 The 3n + 1 problem
- 搞不懂的U-boot
- 以前的代码1
- Ubuntu 12.04不能在华硕F81se系列电脑上安装解决办法