nodejs小记之formidable同步图片文件上传
2016-04-07 11:05
876 查看
本文章只记录过程,不讲解原理。
下面所有的操作都在搭建好的express工程下,express配置参考前面的文章。
首先现在formidable
配置路由
这个时候上传文件,你将跳转另一个页面,然后以json的形式返回文件的信息。
通过
把上传的文件更名上传到你想要的文件夹。
更多服务端操作请参考
formidable使用文档
下面所有的操作都在搭建好的express工程下,express配置参考前面的文章。
创建上传表单
<form action="uoload" method="post" enctype="multipart/form-data"> <input type="file" name="uoload"> <input type="submit" value="提交信息"> </form>
创建upload服务器
在路由中创建upload路由。首先现在formidable
npm install --save formidable
配置路由
app.post("/uploadserver",function(req,res){ form = new formidable.IncomingForm(); form.parse(req, function(err, fields, files) { res.writeHead(200, {'content-type': 'text/plain'}); res.write('received upload:\n\n'); res.end(util.inspect({fields: fields, files: files})); }); });
这个时候上传文件,你将跳转另一个页面,然后以json的形式返回文件的信息。
通过
fs.renameSync(file.path,"public/img/upload/pingtaicover/"+file.name);
把上传的文件更名上传到你想要的文件夹。
写在结尾
formidable插件支持多文件同时上传。更多服务端操作请参考
formidable使用文档
相关文章推荐
- node基础再现--module.exports 和exports
- NUMA node
- ueditor编辑器无法粘人表格,Uncaught TypeMismatchError: Failed to execute ‘removeAttributeNode’ on ‘Element’: T
- nodejs小记之Ueditor的配置
- Yeoman官网新手教程:第一章 搭建开发环境
- el&&el.nodeType!==1意
- lintcode-medium-Swap Two Nodes in Linked List
- 222. Count Complete Tree Nodes
- LeetCode Remove Nth Node From End of List
- 【NodeJS 】Express
- 222. Count Complete Tree Nodes 完全二叉树节点
- 使用supervisor提高nodejs调试效率
- 024 Swap Nodes in Pairs
- leetcode——24—— Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs
- NodeJS、NPM安装配置步骤(windows版本)
- Nodejs Error: Cannot find module 'unicode/category/So'
- nodejs 升级命令
- nodejs之promise书写规范
- LeetCode 237 -Delete Node in a Linked List ( JAVA )