ajax传文件用express的multer接住
2024-09-05 21:26:48
html部分:
//input type设为file
<input type="file" name="file" id="fileInputElement" />
<button id="submit">提交</button>
script部分
var btn = document.getElementById('submit');
var fileInputElement = document.getElementById('fileInputElement'); btn.onclick = function () { var oMyForm = new FormData();
//append来添加文件,
oMyForm.append("afile", fileInputElement.files[]); var oReq = new XMLHttpRequest(); oReq.open("POST", "/test"); //用FormData生成的对象的好处是,send不需要setRequestHeader
oReq.send(oMyForm);
}
后台nodejs部分
const app = express();
const multer = require('multer');
var upload = multer({dest:'file/'})//multer的参数dest表示文件接受后存放的地址 app.post('/test',upload.single('afile'),(req,res)=>{ })
最新文章
- 5Hibernate入门----青软S2SH(笔记)
- linux命令:chmod
- Windows安装Node.Js
- Angular系列----AngularJS入门教程02:静态模板(转载)
- Form_Form Builder开发基于视图页面和自动代码生成包(案例)
- win7系统64位eclipse环境超详细暗黑1.4服务器搭建
- 判断app是否在后台
- Spring安全资料整理列表
- Watch gcc at ubuntu 12,See ELF file header
- Unity Chan Advanced
- 使用静态资源设置UI信息
- TODO、FIXME和XXX转载
- Spring + Spring MVC + Hibernate
- JAVA基础第二组(5道题)
- Webpack自动化工程
- cordova/phonegap/webapp性能优化方法
- WPF中如何调整TabControl的大小,使其跟随Window的大小而改变?
- mysql日期时间函数(常用的)
- 发布逸出 java this 逸出【转】
- LeetCode--018--四数之和(java)
热门文章
- python装饰器的简单理解
- [洛谷P2567] SCOI2010 幸运数字
- unigui ios微信界面错位和点击失灵问题
- POJ 1011 Sticks(搜索 &;&; 剪枝 &;&; 经典)
- codevs 3060 抓住那头奶牛 x
- (3.2)狄泰软件学院C++课程学习剖析三
- CF1019E Raining season
- 使用JLDAP操作LDAP,包含匿名连接、ldif导入导出、获取根节点、对数据的操作、LDAP错误码解析等
- JavaScript异步编程助手:Promise模式
- java.lang.OutOfMemoryError:GC overhead limit exceeded解决方