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 文件上传的更多相关文章

  1. angularjs 文件上传 如何绑定file表单的change?

    ng-change 会失灵 , 唯一的解决方式 是 onchange="angular.element(this).scope().fileNameChanged()"然后利用 n ...

  2. webAPI+angularJS文件上传和下载

    开发框架 前端 angularJS1.6 下载和保存文件FileSaver:https://github.com/eligrey/FileSaver.js/ 后端 .net WebAPI 1 导入Ex ...

  3. AngularJs 文件上传(实现Multipart/form-data 文件的上传)

    <!-- 上传yml文件 --> <div class="blackBoard" ng-show="vm.showUpop==true"> ...

  4. [Angularjs]ng-file-upload上传文件

    写在前面 最近在弄文档库的H5版,就查找了下相关的上传组件,发现了ng-upload的东东,推荐给大家. 系列文章 [Angularjs]ng-select和ng-options [Angularjs ...

  5. AngularJs附件上传下载

    首先:angular-file-upload 是一款轻量级的 AngularJS 文件上传工具,为不支持浏览器的 FileAPI polyfill 设计,使用 HTML5 直接进行文件上传. 第一步: ...

  6. angularjs结合plupload实现文件上传

    转载注明:(罗志强的博客) angularjs的指令directive非常好使,可以很方便的结合各种插件,实现很强大的功能. 今天用到了plupload,就拿它举例吧. 正常的plupload用法应该 ...

  7. [sharepoint]rest api文档库文件上传,下载,拷贝,剪切,删除文件,创建文件夹,修改文件夹属性,删除文件夹,获取文档列表

    写在前面 最近对文档库的知识点进行了整理,也就有了这篇文章,当时查找这些接口,并用在实践中,确实废了一些功夫,也为了让更多的人走更少的弯路. 系列文章 sharepoint环境安装过程中几点需要注意的 ...

  8. jquery.uploadify文件上传组件

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...

  9. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

随机推荐

  1. Eclipse中的项目红叉问题查找记录

    1.先查看项目的validation有没有都勾上,如果都勾上,一般项目下边的文件夹下会显示出来.可以解决. 2.如果项目文件夹下各个红叉都解决了,没有什么报错了.那么可以看下工具的problem标签下 ...

  2. awk-06-常用内置函数

    常用内置函数 示例 1.int 2.sqrt 3.rand rand()并不是每次运行都会产生一个随机数,会一直保持不变 所以需要srand() 函数一起 但是还是有很大的几率会生成一样 4.asor ...

  3. SQL injection:Summary ,Overview and Classification

    What is SQL injection (SQLi)? SQL注入是一种web安全漏洞,让攻击者干扰应用程序对其数据库的查询. 它通常使得攻击者查看他们通常无法检索的数据. 这可能包括属于其他用户 ...

  4. Element Vue 开箱即用框架如何使用-测试开发【提测平台】阶段小结(二)

    微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 上一篇总结了后端服务接口的开发,这篇我们主要来总结下前后端分离开发中的前端部分,主要是开箱即用的框架介绍和之前章节组件的梳理和部分的扩展内 ...

  5. 【AIOT】智能感知--人

    From: https://liudongdong1.github.io/ 1. 人体存在感知 目标:检测环境中的所有人体,标记出每个人体的坐标位置:不限人体数量,适应中低空斜拍.人体轻度遮挡.截断等 ...

  6. 【SpringMVC】@RequestMapping注解

    @RequestMapping注解的源码 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNT ...

  7. 【springcloud】springcloud Greenwich SR4版本笔记

    springcloud Greenwich SR4版本笔记 本文只记录实际版本,配置,pom,代码以及注意事项.别的在其他springcloud 的F版本中已有详述. 示例代码地址:https://g ...

  8. 信号量-Semaphore、SemaphoreSlim

    核心类:Semaphore,通过int数值来控制线程个数. * 通过观察构造函数 public Semaphore(int initialCount, int maximumCount);: * in ...

  9. Hibernate的一级缓存和二级缓存

    Fist level cache: This is enabled by default and works in session scope. Read more about hibernate f ...

  10. LeetCode入门指南 之 二叉树

    二叉树的遍历 递归: void traverse (TreeNode root) { if (root == null) { return null; } //前序遍历位置 traverse(root ...