前台代码使用jQuery的ajax:

<script type="text/javascript">
$(function(){
$('#file_upload').click(function(){

var data = new FormData();
var files = $('#file')[0].files;

if (files) {
data.append('codecsv',files[0]);
}

$.ajax({
cache: false,
type: 'post',
dataType: 'json',
url:'upload',
data : data,
contentType: false,
processData: false,
success : function () {

}
});
});

})

</script>
<table style='width: 100%;height: 100%'>
<tr>
<td style='width:800px;text-align: center;'>
<input id='file' type="file">
<input id='file_upload' type="button" value="upload">
</td>
</tr>
</table>

上传文件的nodejs express的后台

Node.js代码

var express = require('express');
var fs = require('fs');
var path = require('path');

//createServer
var app = module.exports = express.createServer();

app.configure(function(){
app.use(express.bodyParser({uploadDir:'c:\\aa'}));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.post('/:service?', function(req, res){
if (req.files && req.files.codecsv != 'undifined') {
var temp_path = req.files.codecsv.path;
if (temp_path) {
fs.readFile(temp_path, 'utf-8', function(err, content) {
//文件的内容
console.log('content',content);
// 删除临时文件
fs.unlink(temp_path);
});
}
}

});

app.listen(4000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});

最新文章

  1. ASP.NET MVC4入门到精通系列目录汇总
  2. Spring 资源文件处理
  3. Python 2.7_Second_try_爬取阳光电影网_获取电影下载地址并写入文件 20161207
  4. [转载]百度编辑器-Ueditor使用
  5. git中进入带有空格的目录下的解决办法
  6. Gulp使用指南
  7. 单点登录sso规范
  8. java web的一些特殊用法(一)
  9. C语言中的volatile
  10. Linux学习之六-Yum命令的使用
  11. GitLab Development Kit 环境搭建
  12. 网站开发进阶(六)JSP两种声明变量的区别
  13. Vue.set() this.$set()引发的视图更新思考
  14. 史上最污技术解读,让你秒懂IT术语(转载)
  15. 解决easyui combobox赋值boolean类型的值时,经常出现的内容显示的value而不是text的bug
  16. ASP.NET Core MVC四种枚举绑定方式
  17. 【翻译】关于vertical-align所有你需要知道的
  18. Java常用API-高级
  19. &lt;转&gt;Python: and、or以及and-or
  20. jquery 选择唯一值 选择器“”非“用法

热门文章

  1. Alpha阶段敏捷冲刺①Scrum 冲刺博客
  2. 性能分析_linux服务器CPU_中断
  3. UDJC用户自定义Java类
  4. ci钩子
  5. chdir
  6. [转帖]AMD、英特尔为何争相走向胶水多核处理器?真相在此
  7. Nmap用法实例
  8. The Best Path HDU - 5883(欧拉回路 &amp;&amp; 欧拉路径)
  9. codevs2875RY哥查字典
  10. hdu6057 Kanade&#39;s convolution 【FWT】