angularjs 的可拆剪的上传头像 up-file-upload
首先:引入1.
2.
3.
然后:var app = angular.module(“xxj”, [“ngRoute”, “mobile-angular-ui”, ‘ui.bootstrap’, “xxService”, “xxDirective”, “xxFilter”,’ngFileUpload’, ‘ngImgCrop’]); //[]表示注入模块
在html页面:
然后js的是://上传头像
var serachInfo = function() {
xxHttp.get(“/cust/auth/user”, false, function(payload) {
$rootScope.myUserInfo = payload;
});
}
serachInfo();
//获得文件服务器授权路径
xxHttp.get(“/cust/free/upload_file/sig”, true, function(payload) {
$rootScope.UploadFileSig = payload;
}, {
targetFolder: ‘aa’
});
//提交
$scope.modifyIcon = function(name) {
xxHttp.put(“/cust/auth/user_modify”, true, function(payload) {
$rootScope.msgbox({
title: “修改头像”,
content: “修改成功.”,
ok: function() {
serachInfo();
}
});
}, {
account: $rootScope.myUserInfo.account,
mobile: $rootScope.myUserInfo.mobile,
icon: name
})
};
//上传头像文件
$scope.upload = function(dataUrl, name) {
var suffix = name.substr(-5); //substr(-5)截取后五位
var newName = $rootScope.myUserInfo.id + new Date().getTime() + suffix;
Upload.upload({
//服务端接收
url: $rootScope.UploadFileSig,
//上传的文件
data: {
file: Upload.dataUrltoBlob(dataUrl, newName)
},
}).success(function(data, status, headers, config) {
$scope.modifyIcon(newName);
//上传成功
$scope.result = data;
//跳转回去
SharedState.turnOff(“openChangePictureModal”);
}).error(function(data, status, headers, config) {
//上传失败
$scope.errorMsg = status + ‘: ‘ + data;
});
};
详情请查看github的原版:https://github.com/danialfarid/ng-file-upload
还没有评论,来说两句吧...