700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > angularjs java 文件上传_AngularJS 文件上传控件 ng-file-upload(示例代码)

angularjs java 文件上传_AngularJS 文件上传控件 ng-file-upload(示例代码)

时间:2018-12-17 04:04:37

相关推荐

angularjs java 文件上传_AngularJS 文件上传控件 ng-file-upload(示例代码)

网上可以找到的 AngularJS 的文件上传控件有两个:

angular-file-upload:/nervgh/angular-file-upload

ng-file-upload:/danialfarid/ng-file-upload

这两个非常类似,连js文件的结构都是一样的。核心的js是.min.js,还都有一个-shim.min.js,用来支持上传进度条和上传暂停等高级功能。

按道理讲shim.js应该是可加可不加,但实测-shim.min.js必须包含,否则有js文件加载问题。但是angular-file-upload-shim.min.js这个文件在github上不存在!!!

所以用ng-file-upload!用ng-file-upload!用ng-file-upload!

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

特性

支持上传进度,在上传的时候,可以取消或者中止,支持文件拖拽(HTML5),目录拖拽(weikit),CORS, PUT(html5)/POST 方法

支持使用 Flash polyfill FileAPI 跨浏览器上传 (HTML5 和 non-HTML5) 。允许客户端在上传之前验证或者修改文件。

当文件的内容类型使用 $upload.http()时,支持直接上传到 CouchDB,imgur 等等。支持 Angular http POST/PUT 请求的进度事件

轻量级,使用常规的 $http 来上传(支持非 HTML5 浏览器),所以提供所有 Angular $http 功能

例子

文件上传

varapp=angular.module(‘app‘, [‘ngFileUpload‘]);

app.controller(‘FileController‘,function($scope, Upload) {

$scope.uploadImg= ‘‘;//提交

$scope.submit= function() {

$scope.upload($scope.file);

};

$scope.upload= function(file) {

$scope.fileInfo=file;

Upload.upload({//服务端接收

url:‘Ashx/UploadFile.ashx‘,//上传的同时带的参数

data: {‘username‘: $scope.username},//上传的文件

file: file

}).progress(function(evt) {//进度条

varprogressPercentage=parseInt(100.0 *evt.loaded/evt.total);

console.log(‘progess:‘ +progressPercentage+ ‘%‘ +evt.config.file.name);

}).success(function(data, status, headers, config) {//上传成功

console.log(‘file‘ +config.file.name+ ‘uploaded. Response:‘ +data);

$scope.uploadImg=data;

}).error(function(data, status, headers, config) {//上传失败

console.log(‘error status:‘ +status);

});

};

});

当前上传用户:

Select

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。