2016-08-18 3 views
0

Ich lade etwa 10 Fotos auf einmal hoch (Fotos reichen von 800kb - 1000kb pro Foto).angularjs ng-resource Asynchron Upload

Mein Problem ist, dass die App nach etwa 5 Sekunden abstürzt.

Wie lade ich die Fotos asynchron hoch und verbessere vielleicht die Leistung der App?

-Controller

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'); 
       } 
     }); 
     } 
     }) 

Fabrik

appcon.factory('PostImg', function($resource) { 
return $resource('http://192.168.0.1/Service.svc/BOB'); 
}); 

Antwort

0

Können Sie cordova-plugin-File-Transfer versuchen. Bitte beachten Sie, dass es nur im Telefon funktioniert.

http://ngcordova.com/docs/plugins/fileTransfer/

+0

Ich verwende einen REST-Service und $ resource funktioniert großartig mit meinem Service. Auch habe ich Dateiübertragung verwendet, aber es funktioniert nicht so gut auf IOS, wie ich es auch möchte. Mein Problem ist, dass alles auf einmal hochgeladen wird, also muss ich sie asynchron hochladen. –

+0

destinationType: Camera.DestinationType.DATA_URL Das Laden aller Bilder als Daten im Arbeitsspeicher kostet viel Speicherplatz und führt zum Absturz Ihrer App. Also nur Weg ist es, Telefonspeicher zu speichern und sie zu übertragen. Dafür müssen Sie einige native Plugins verwenden. Ich kann keinen anderen Weg vorschlagen. Bitte recherchieren Sie und teilen Sie Ihre Erkenntnisse, damit sie anderen helfen können. Vielen Dank.. –

Verwandte Themen