angularjs 文件上传
github连接地址:https://github.com/danialfarid/ng-file-upload
核心代码:
html:
<div class="form-group">
<label>源文件:</label>
<input class="form-control h30 w356" ng-model="data.filePath"/>
<select class="form-control h30 w143">
<option value="">1</option>
<option value="">2</option>
</select>
<div class="button" ngf-select="fileChanged($file)">Upload on file select</div>
</div>
js:
//var app = angular.module('main.app', ['bw.paging', 'cbc.datePicker', 'ngFileUpload']);
//app.controller('main-controller', function ($scope, $http, $log, $rootScope,
Upload) {
$scope.fileChanged = function (file) {
Upload.upload({
url: '/ImportSettlement/Upload',
data: { file: file }
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
});
}
后台代码:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file == null)
{
return Content("没有文件!", "text/plain");
}
var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName));
try
{
return Content("上传异常 !", "text/plain");
//file.SaveAs(fileName);
////tm.AttachmentPath = fileName;//得到全部model信息
//tm.AttachmentPath = "../upload/" + Path.GetFileName(file.FileName);
////return Content("上传成功!", "text/plain");
//return RedirectToAction("Show", tm);
}
catch
{
return Content("上传异常 !", "text/plain");
}
}
上述代码兼容IE10及以上浏览器,兼容IE9代码如下:
Html:
引入ng-upload-file组件
<script src="/Scripts/angular/FileUpload/ng-file-upload.min.js"></script>
<script>
//optional need to be loaded before angular-file-upload-shim(.min).js
FileAPI = {
debug: true,
// forceLoad: true,
// html5: false, //to debug flash in HTML5 browsers
jsUrl: '/Scripts/angular/FileUpload/FileAPI.min.js',
flashUrl: '/Scripts/angular/FileUpload/FileAPI.flash.swf',
};
</script>
<!-- for no html5 browsers support -->
<script src="/Scripts/angular/FileUpload/ng-file-upload-shim.min.js"></script>
--------------------上传部分
<div class="button" ngf-select="fileChanged($file)">Upload on file select</div>
js执行
//var app = angular.module('main.app', ['bw.paging', 'cbc.datePicker', 'ngFileUpload']);
//app.controller('main-controller', function ($scope, $http, $log, $rootScope, Upload) {
$scope.fileChanged = function (file) {
Upload.upload({
url: '/ImportSettlement/Upload',
data: { file: file }
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
});
}
后台接收:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file == null)
{
return Content("没有文件!", "text/plain");
}
var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName));
try
{
return Content("上传异常 !", "text/plain");
//file.SaveAs(fileName);
////tm.AttachmentPath = fileName;//得到全部model信息
//tm.AttachmentPath = "../upload/" + Path.GetFileName(file.FileName);
////return Content("上传成功!", "text/plain");
//return RedirectToAction("Show", tm);
}
catch
{
return Content("上传异常 !", "text/plain");
}
其他相关
http://www.cnblogs.com/zhouhb/p/3906714.html
http://www.cnblogs.com/zhangxiaolei521/p/5985790.html
angularjs 文件上传的更多相关文章
- angularjs 文件上传 如何绑定file表单的change?
ng-change 会失灵 , 唯一的解决方式 是 onchange="angular.element(this).scope().fileNameChanged()"然后利用 n ...
- webAPI+angularJS文件上传和下载
开发框架 前端 angularJS1.6 下载和保存文件FileSaver:https://github.com/eligrey/FileSaver.js/ 后端 .net WebAPI 1 导入Ex ...
- AngularJs 文件上传(实现Multipart/form-data 文件的上传)
<!-- 上传yml文件 --> <div class="blackBoard" ng-show="vm.showUpop==true"> ...
- [Angularjs]ng-file-upload上传文件
写在前面 最近在弄文档库的H5版,就查找了下相关的上传组件,发现了ng-upload的东东,推荐给大家. 系列文章 [Angularjs]ng-select和ng-options [Angularjs ...
- AngularJs附件上传下载
首先:angular-file-upload 是一款轻量级的 AngularJS 文件上传工具,为不支持浏览器的 FileAPI polyfill 设计,使用 HTML5 直接进行文件上传. 第一步: ...
- angularjs结合plupload实现文件上传
转载注明:(罗志强的博客) angularjs的指令directive非常好使,可以很方便的结合各种插件,实现很强大的功能. 今天用到了plupload,就拿它举例吧. 正常的plupload用法应该 ...
- [sharepoint]rest api文档库文件上传,下载,拷贝,剪切,删除文件,创建文件夹,修改文件夹属性,删除文件夹,获取文档列表
写在前面 最近对文档库的知识点进行了整理,也就有了这篇文章,当时查找这些接口,并用在实践中,确实废了一些功夫,也为了让更多的人走更少的弯路. 系列文章 sharepoint环境安装过程中几点需要注意的 ...
- jquery.uploadify文件上传组件
1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...
- 11、Struts2 的文件上传和下载
文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...
随机推荐
- appium自动化测试(5)-一些pyhon操作
1.套件的问题 将所有的测试用例加进去,会一个个执行,用于用例名字没有规范test开头的时候 def suite(): suite = unittest.TestSuite suite.addTest ...
- Vulhub-DC-1靶场
前言: DC-1靶场是Vulhub系一款渗透测试的实战靶场,拥有五个Flag.本篇博客讲述了如何拿去这五个Flag,并详细描述其中的注意点. 实验环境: 虚拟机环境:virtualbox 虚拟机1:D ...
- Use iTunes on Linux
Today I installed iTunes (Windows installer) via wine. But after installation it didn't work. Then I ...
- Golang语言系列-13-常用内置包
常用内置包 net/http包 http请求和响应 http服务端 main.go文件 package main import ( "fmt" "io/ioutil&qu ...
- 深入理解HTTP请求流程
以前写过一篇博客,叫做HTTP的报文分析:https://blog.csdn.net/ZripenYe/article/details/119593269但是感觉还是不太深入.不够全面,顶多了解个大概 ...
- 某次无中生有的getshell过程
0x01 写在前面 某次对目标的渗透中,发现了疑似前台上传漏洞,反复测试后无法成功利用,多方探寻最终成功getshell的过程. 0x02 信息收集 这次的目标是一个APP分发平台,对这一类的网站接触 ...
- NOIP 模拟 6 考试总结
T1 这道题是一道裸的暴力,考场写挂了 \(5pts\) 原因竟是忘了删注释,难受 题解 T2 这道题是一道启发式合并,没想出来,拿了个暴力分跑了 题解 T3 这道题就是一道数学期望,想出来就水得很, ...
- Node + Selenium 报错 UnhandledPromiseRejectionWarning: Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:5319
安装selenium-webdriver npm i selenium-webdriver 当前安装版本: "selenium-webdriver": "^4.0.0-a ...
- qt 中的QlistWidget
- jdbc获取PreparedStatement最终执行的sql语句
//直接打印PreparedStatement对象 System.out.println(ps); 输出结果: com.mysql.jdbc.JDBC42PreparedStatement@5f205 ...