我一次上传大约10张照片(照片范围为800kb - 每张照片1000kb)。
我的问题是,应用程序在大约5秒钟后崩溃。
如何异步上传照片并提高应用程序的性能?
控制器
appcon.controller('myCtrl', function($scope, $state, $cordovaCamera, $ionicPopup, PostImg){
$scope.postData = [];
var truckid = "%" + window.localStorage['truckid'] + "%";
$scope.start = function() {
document.addEventListener("deviceready", function () {
var options = {
quality: 200,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1000,
targetHeight: 1000,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var file = imageData;
$scope.postData.push({file});
}, function(err) {
console.log('4 error');
});
}, false);
}
$scope.upload = function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Continue?',
template: 'Are you sure you want to Send Images?'
});
confirmPopup.then(function(res) {
if(res) {
$scope.postData.push({truckid});
var post = new PostImg($scope.postData);
post.$save(function(postObject) {
var alertPopup = $ionicPopup.alert({
title: 'Images Send !',
buttons: [{
text: 'Continue with Check In?',
type: 'button-positive'
}]
});
alertPopup.then(function(res) {
});
});
}
else {
console.log('You are not sure');
}
});
}
})
工厂
appcon.factory('PostImg', function($resource) {
return $resource('http://192.168.0.1/Service.svc/BOB');
});
答案 0 :(得分:0)
你能试试cordova-plugin-file-transfer吗?请注意,它仅适用于手机。