2016-11-07 1 views
0

Ich habe ein Ionic Framework, wo ich das FileTransser-Modul geladen habe, damit ich ein Bild aufnehmen und hochladen kann. Der Teil "Fotografieren" funktioniert perfekt.ionic FileTransfer gibt kein Ergebnis/Fehler/Feedback, und dann tut die Erfolgsfunktion

Wenn ich auf das Bild klicke, um es hochzuladen, feuert es das Overlay "Busy uploading", dann wird es ausgeblendet und es wird die unvollständige Funktion ausgeführt.

Das Problem ist, dass der eigentliche Upload-Teil nichts tut. Keine Fehler, keine Notizen, nichts in meinen Logs, keine tatsächliche XHR resouce (oder irgendeine Ressource). Dies macht es ziemlich schwierig zu debuggen. Könnte mir jemand einen Stoß in die richtige Richtung geben?

Ps: Ich tue dies auf meinem Android, mit Chrome debugconsole

$scope.takePicture = function() { 
    var options = { 
     quality: 90, 
     destinationType: Camera.DestinationType.FILE_URL, 
     sourceType: Camera.PictureSourceType.CAMERA 
    }; 

    $cordovaCamera.getPicture(options).then(
     function(imageData) { 
      $scope.picData = imageData; 
      $scope.ftLoad = true; 
      //~ $localStorage.setItem('fotoUp', imageData); 
      //~ $localStorage.fotoUp = imageData; 
      $ionicLoading.show({template: 'Loading picture...', duration:500}); 
     }, 
     function(err){ 
      $ionicLoading.show({template: 'Error loading...', duration:500}); 
     } 
    ) 
} 
//-------------------------- 
// Upload the photo 
$scope.uploadPicture = function() { 
    $scope.upload = {}; 
    $ionicLoading.show({template: 'Bezig met uploaden...'}); 
    var fileURL = $scope.picData; 
    var options = new FileUploadOptions(); 
    options.fileKey = "file"; 
    options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1); 
    options.mimeType = "image/jpeg"; 
    options.chunkedMode = true; 


    var ft = new FileTransfer(); 
    ft.upload(fileURL, "https://www.example.com/recieve_photos.php", viewUploadedPictures, function(error) { 
     $ionicLoading.show({template: 'connection error...'}); 
     $ionicLoading.hide(); 
    }, options); 
} 

var viewUploadedPictures = function($) { 
    $ionicLoading.show({template: 'Get uploaded pictures...'}); 
    $http.get('https://www.example.com/recieve_photos.php') 
     .then(function (response){ 
      $scope.upload.result = response.data 
     }).catch(function(error){ 
      $scope.error = error; 
     }); 
    $ionicLoading.hide(); 
} 

Antwort

0

ich anderer Dokumentation gefunden habe, die zeigten, wie das Ergebnis verwenden/Antwort mehr zu debuggen:

var win = function (r) { 
     console.log("Code = " + r.responseCode); 
     console.log("Response = " + r.response); 
     console.log("Sent = " + r.bytesSent); 
     $ionicLoading.hide(); 
    } 

    var fail = function (error) { 
     alert("An error has occurred: Code = " + error.code); 
     console.log("upload error source " + error.source); 
     console.log("upload error target " + error.target); 
     $ionicLoading.hide(); 
    } 
    var ft = new FileTransfer(); 
    ft.upload(fileURL, encodeURI("https://www.example.com/recieve_photos.php"), win, fail, options); 

Danach wusste ich, ich habe einen Fehlercode 3, mit dem ich den Fortschritt fortsetzen konnte.

Verwandte Themen