var http = require('http')
,formidable = require('formidable')
,fs = require('fs')
, sys = require('sys');
http.createServer(function (req, res) {
// set up some routes
switch(req.url) {
case '/':
// show the user a simple form
console.log("[200] " + req.method + " to " + req.url);
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.write('<html><head><title>Hello Noder!</title></head><body>');
res.write('<h1>Welcome Noder, who are you?</h1>');
res.write('<form enctype="multipart/form-data" action="/formhandler" method="post">');
res.write('Name: <input type="text" name="username" value="John Doe" /><br />');
res.write('Age: <input type="text" name="userage" value="99" /><br />');
res.write('File :<input type="file" name="upload" multiple="multiple"><br>');
res.write('<input type="submit" />');
res.write('</form></body></html');
res.end();
break;
case '/formhandler':
if (req.method == 'POST') {
console.log("[200] " + req.method + " to " + req.url);
req.on('data', function(chunk) {
console.log("Received body data:");
// console.log(chunk.toString());
});
var form = new formidable.IncomingForm();
form.parse(req, function(err,fields, files) {
console.log('in if condition'+sys.inspect({fields: fields, files: files}));
fs.writeFile(files.upload.name, files.upload,'utf8', function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end();
});
req.on('end', function() {
// empty 200 OK response for now
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.end();
});
} else {
console.log("[405] " + req.method + " to " + req.url);
res.writeHead(405, "Method not supported", {'Content-Type': 'text/html'});
res.end('<html><head><title>405 - Method not supported</title></head><body><h1>Method not supported.</h1></body></html>');
}
break;
default:
res.writeHead(404, "Not found", {'Content-Type': 'text/html'});
res.end('<html><head><title>404 - Not found</title></head><body><h1>Not found.</h1></body></html>');
console.log("[404] " + req.method + " to " + req.url);
};
}).listen(8081)
分享到:
相关推荐
Node.js文件管理器这是一个简单的文件管理器,用于按类别下载和上传服务器上的文件。 文件管理器由Node.js和Express组成。 您可以对其进行更改,改进和自行发布。 您也可以使用此简单的文件服务器与每个设备(例如...
用于演示如何使用Node.js和jQuery完成不刷新的文件上传。 ###相关文章 请参见上的博文。 ###应用启动 如果系统中已经安装了git,则可以用下面的命令克隆: $ git clone ...
Socket.IO文件上传该模块提供了将文件从浏览器上载到运行Socket.IO的Node.JS服务器的功能。 在整个过程中,如果他们的浏览器支持WebSocket,则用户将不会提交单个HTTP请求。 支持Socket.IO 0.9及更高版本。 预期的...
零依赖节点文件上传 纯粹的nodejs文件上传,零依赖。...cd node-file-upload 运行服务器 npm start 要不就 node index.js 测试 curl --upload-file ./<file> http://127.0.0.1:3000/ 执照 麻省理工学院:copyright:
File-upload-Angular2-Node.js 使用angular 2和node.js上传文件 ##快速设置 git clone https://github.com/rahil471/File-upload-Angular2-Nodejs.git file-upload 导航到节点应用程序cd file-upload/node-app ...
使用HTML5和Node.js的文件上传演示。 跑步, 将此存储库克隆到本地计算机。 打开一个终端,切换到克隆存储库的本地文件夹。 键入npm install ,然后按Enter键。 然后输入grunt ,然后按enter 。 或者,键入...
主题介绍大事记溪流文件系统操作上载档案模组NPM 表示快速路线套接字使用Redis持久化数据建议的先决条件介绍/* Node.js - Allows you to build scalable network applications using JavaScript on the server-side....
Node.js简单文件上传 依存关系 表达 ejs fs 磨碎机 跑 > git clone https://github.com/Majidkn/nodejs-simple-file-upload.git > cd nodejs-simple-file-upload > npm install > npm start 该应用程序将在:3000
upload-file-简化的文件上传 一些选项是从借用的 var Upload = require ( 'upload-file' ) ; 安装 npm install upload-file --save 快速演示 app . post ( '/upload' , function ( req , res ) { var upload = new ...
本文介绍了Node Js 使用KOA处理form-data格式传输过来的文件,分享给大家。...form表单【注意:enctype=”multipart/form-data”】上传文件时,首先会将文件上传到你本机的temp目录,然后执行move_upload_file
一个用于在 node.js 中上传文件的演示应用程序。 文件通过multer上传。 文件上传到'./uploads' 。 需要对'/'的 multipart/formdata POST请求。 安装: npm install 使用以下命令运行服务器: npm start
Deno等)课程大纲入门JavaScript刷新器Node.js基础高效发展使用Express.js 模板引擎模型视图控制器(MVC) 先进的路线和模型节点+ SQL(MySQL) 使用续集节点+ NoSQL(MongoDB) 使用猫鼬会话和Cookie 认证方式发送...
文件上传lambda 文件上传Lambda-写在AWS Chalice和Node.js中
在 Node.js 和 socket.io 上运行的基本文件上传工具 它是如何工作的 ? 上传开始时,选定的文件被拼接成小块。 然后,接头被发送到服务器。 当服务器收到数据时,将其写入磁盘,服务器请求新的块。 执行相同的循环...
google 了一番之后, 明白了浏览器无非就是利用http协议来给服务器传输数据, 具体协议就是《RFC 1867 – Form-based File Upload in HTML》, 在浏览器上通过form 表单来上传文件就是通过这个协议,我们可以先看看...
这是关于如何实现创建将用户的文件提交到Node.js应用程序服务器上的临时文件夹的Web表单的博客文章的一部分。 博客文章/教程 Node.js解决方案依赖性 -表达-multer -body-parser 安装此解决方案以在本地运行 FORK / ...
从React.js上载文件到Node.js的简单技术。 在此仓库中,我将研究如何以安全,有效的方式使用React.js上传文件。 克隆仓库 :rocket: :注意:您也可以从头开始。 在终端...
file_upload_app如何使用$ npm install$ node index.js您可以访问http://localhost:8888并上传您的图像文件。参考
烈火 一个非官方软件包,可以轻松处理Node.js上的Backblaze B2 API: import Bucket from "backblaze" ;const bucket = Bucket ( "bucket-name" , { id : process . env . B2_ID , key : process . env . B2_KEY} ) ...
fileuploader:漂亮而强大HTML文件上传工具。 一个jQuery,PHP和Node.js插件,可将标准输入转换为页面上具有革命性的精美字段