angularjs手机webapp 利用input拍照,图库选择上传图片
2017-06-07 11:13
483 查看
1.html
<div class="col col-50" style="text-align: center">
<img src="{{imageUrl}}{{fileUrl}}" width="60" height="60" style="border-radius: 30px" >
<div id="myupload">
<input id="uploadfile" file-model="myFile" type="file" name="file" accept="image/*" style="opacity: 0;position: absolute;font-size: 100px;right: 60%;top: 44px;width: 50%;height: 100px">
</div>
<p style="margin-top: 5px">ATM会员</p>
</div>
2.directive
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs, ngModel) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(event){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
scope.file = (event.srcElement || event.target).files[0];
scope.getFile(scope.file);
$('#uploadfile').val(''); //发现拍照上传后再次拍照不会调用change方法,加入这行代码可解决
});
}
};
}])
3.controller
$scope.getFile = function (file) {
$ionicLoading.show({
template: '<ion-spinner icon="ios-small"></ion-spinner>'+'图片上传中,请稍候...',
duration: 3000
});
Upload.upload({
url: ApiUrl.url+'/User_login/image',
data: {file: file}
}).then(function (resp) {
$scope.fileUrl = resp.data;
toastr.success( "上传成功");
localStorage.setItem("avatar",$scope.fileUrl);
console.log($scope.imageUrl+$scope.fileUrl)
$ionicLoading.hide();
// console.log('Success ' + resp.data.file_name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
$ionicLoading.hide();
toastr.warning( resp.data.tips,"上传失败");
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
上传用的ng-file-upload插件 地址:https://github.com/danialfarid/ng-file-upload点击打开链接
<div class="col col-50" style="text-align: center">
<img src="{{imageUrl}}{{fileUrl}}" width="60" height="60" style="border-radius: 30px" >
<div id="myupload">
<input id="uploadfile" file-model="myFile" type="file" name="file" accept="image/*" style="opacity: 0;position: absolute;font-size: 100px;right: 60%;top: 44px;width: 50%;height: 100px">
</div>
<p style="margin-top: 5px">ATM会员</p>
</div>
2.directive
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs, ngModel) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(event){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
scope.file = (event.srcElement || event.target).files[0];
scope.getFile(scope.file);
$('#uploadfile').val(''); //发现拍照上传后再次拍照不会调用change方法,加入这行代码可解决
});
}
};
}])
3.controller
$scope.getFile = function (file) {
$ionicLoading.show({
template: '<ion-spinner icon="ios-small"></ion-spinner>'+'图片上传中,请稍候...',
duration: 3000
});
Upload.upload({
url: ApiUrl.url+'/User_login/image',
data: {file: file}
}).then(function (resp) {
$scope.fileUrl = resp.data;
toastr.success( "上传成功");
localStorage.setItem("avatar",$scope.fileUrl);
console.log($scope.imageUrl+$scope.fileUrl)
$ionicLoading.hide();
// console.log('Success ' + resp.data.file_name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
$ionicLoading.hide();
toastr.warning( resp.data.tips,"上传失败");
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
上传用的ng-file-upload插件 地址:https://github.com/danialfarid/ng-file-upload点击打开链接
相关文章推荐
- 图片上传时,在图库选择图片和拍照返回时经常闪退。
- 选择手机中的一张照片或拍照上传图片(超高清晰度)
- android 拍照或者图库选择 压缩后 图片 上传
- 选择图片或拍照并将其利用RecyclerView展示并上传至指定服务器
- 安卓实现拍照、在手机中选择图片通过webservice上传图片到服务器
- 通过照相机拍照或者图库选择图片上传给服务器作为头像
- android 手机拍照上传项目的开发-----JAVA利用socket传图片给linux服务器
- PHP 使用 微信JSSDK 拍照选择图片接口 利用localid预览时 安卓手机正常显示 iOS手机不显示
- 安卓实现拍照、在手机中选择图片通过webservice上传图片到服务器
- Android拍照得到全尺寸图片并进行压缩/拍照或者图库选择 压缩后 图片 上传
- 利用系统相机和图库打造3分钟完成拍照,图片裁剪以及视频资源上传功能
- android学习笔记----解决android有的手机拍照后上传图片被旋转的问题
- 手机拍照上传图片问题
- java读取图片属性---判断手机拍照上传的图片是否被翻转
- 解决android有的手机拍照后上传图片被旋转的问题
- android选择图片或拍照图片上传到服务器(包括上传参数)
- 解决android有的手机拍照后上传图片被旋转的问题
- phonegap 拍照或者选择图片 上传+ 后台接收图片和参数代码
- android有的手机拍照后上传图片被旋转的问题
- android选择图片或拍照图片上传到服务器(包括上传参数) (转)