2013-04-30 10 views
6

ich ein Bild nehme (oder aus der Bibliothek auswählen) mit PhoneGap API mit dem folgende drictive:Lade den Inhalt des Bildes von der Kamera in eine Datei

MyApp.directive('Camera', function() { 
    return { 
     restrict: 'A', 
     require: 'ngModel', 
     link: function(scope, elm, attrs, ctrl) { 
      elm.bind('click', function() { 
       navigator.camera.getPicture(function (imageURI) 
       { 
        scope.$apply(function() { 
         ctrl.$setViewValue(imageURI); 
        }); 
       }, function (err) { 
        ctrl.$setValidity('error', false); 
       }, 
       //Options => http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera 
       { quality: 50, 
        destinationType:Camera.DestinationType.FILE_URI      
       }) 
      }); 
     } 
    }; 
}); 

Welche Rückkehr mir eine URI, das aussieht wie, Ripple Emulator auf Chrom, das ich sehe, diesen URI einzufügen.

blob:http%3A//localhost%3A8080/8e18de30-d049-4ce2-ae88-8500b444581e 

Mein Problem wird geladen diesen URI

$scope.updateUserProfile = function (user) { 

     var myPicfile = $http.get(user.myPicture); 

     dataService.uploadPicture . . . some code to update the picture to Parse 

    } 

* Hinweis: I cannot use phonegap filetransfer together with parse.com :

Als ich tun, dass ich bekommen:

enter image description here

ich meine Anfrage mache wie :

uploadPicture: Funktion uploadPicture (Benutzer, Rückruf) { var serverUrl = 'https://api.parse.com/1/files/' + user.Nick;

Haben Sie eine Idee, wie Sie den Inhalt des Bildes in eine Datei bekommen, die ich dann problemlos auf Parse.com hochladen kann?

Danke!

+0

prüfen diesen [Speicher Foto auf SD-Karte Captured] (http://stackoverflow.com/questions/14928202/save-image-in-local-storage-phonegap/16648829#16648829) –

Antwort

3

Endlich arbeite ich daran herum, da mein ultimatives Ziel war, es mit phonegap zu verwenden, with the info in this post. . Vielen Dank an Raymond Camden!

function gotPic(data) { 

window.resolveLocalFileSystemURI(data, function(entry) { 

var reader = new FileReader(); 

reader.onloadend = function(evt) { 
    var byteArray = new Uint8Array(evt.target.result); 
    var output = new Array(byteArray.length); 
    var i = 0; 
    var n = output.length; 
    while(i < n) { 
     output[i] = byteArray[i]; 
     i++; 
    }     
    var parseFile = new Parse.File("mypic.jpg", output); 

    parseFile.save().then(function(ob) { 
      navigator.notification.alert("Got it!", null); 
      console.log(JSON.stringify(ob)); 
     }, function(error) { 
      console.log("Error"); 
      console.log(error); 
     }); 

} 

reader.onerror = function(evt) { 
     console.log('read error'); 
     console.log(JSON.stringify(evt)); 
    } 

entry.file(function(s) { 
    reader.readAsArrayBuffer(s); 
}, function(e) { 
    console.log('ee'); 
}); 

}); 
} 
+0

großen Dank funktioniert! –

Verwandte Themen