Upload photo with cordova file and camera


#1

I’m building an app with an option to upload and get photo by camera or gallery.
I’m using cordova file and cordova camera plugin succesfully installed on ionic project.

in app.js i’m starting the plugin so:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
	var pictureSource;
	var destinationType;
	pictureSource = navigator.camera.PictureSourceType;
	destinationType = navigator.camera.DestinationType;
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

and this is my controller code:

.controller('upPhoto', function($scope, $http, $ionicLoading, $localstorage) {   
$scope.takePicture = function(){
	alert("cliccato prendi");
        navigator.camera.getPicture(
            function(uri) {
                var img = document.getElementById('camera_image');
				var btnUp = document.getElementById('uploaded');
                img.style.visibility = "visible";
				btnUp.style.visibility = "visible";
                img.style.display = "block";
				btnUp.style.display = "block";
                img.src = uri;
				$ionicLoading.show({template: 'Foto acquisita...', duration: 1000});
					return false
            },
            function(e) {
                $ionicLoading.show({template: 'Errore durante il caricamento...', duration: 1000});
					return false
            },
            {quality: 40, destinationType: destinationType.FILE_URI});
    };
	$scope.selectPicture = function() {
		alert("cliccato seleziona");
        navigator.camera.getPicture(
            function(uri) {
                var img = document.getElementById('camera_image');
				var btnUp = document.getElementById('uploaded');
                img.style.visibility = "visible";
				btnUp.style.visibility = "visible";
                img.style.display = "block";
				btnUp.style.display = "block";
                img.src = uri;
                $ionicLoading.show({template: 'Immagine caricata...', duration: 1000});
					return false
            },
            function(e) {
                $ionicLoading.show({template: 'Errore del server o immagine troppo grande...', duration: 1000});
					return false
            },
            {quality: 40, destinationType: destinationType.FILE_URI, sourceType: pictureSource.PHOTOLIBRARY});
    };
	
    $scope.uploadPicture = function() {
		alert("cliccato carico");
        var img = document.getElementById('camera_image');
        var imageURI = img.src;
        if (!imageURI || (img.style.display == "none")) {
			$ionicLoading.show({template: 'Scatta una foto o scegline una dalla galleria...', duration: 1000});
					return false}
        server = "http://www.mimanchitu.it/public/phonegap/upload.php";
        if (server) {
			
            var options = new FileUploadOptions();
			$ionicLoading.show({template: 'Attendi qualche secondo...', duration: 500});
            options.fileKey="file";
            options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType="image/jpeg";
            options.chunkedMode = false;
			options.headers = {Connection: "close"};
			var params = new Object();
         	params.value1 = "Amministratore";
          	params.value2 = "1"
          	options.params = params;
            // Transfer picture to server
            var ft = new FileTransfer();
            ft.upload(imageURI, server, function(r) {
				$ionicLoading.show({template: 'Caricamento avvenuto...', duration: 1000});
					viewUploadedPictures();
					return false}, 
			
			function(error) {
				$.ui.showMask('Caricamento non riuscito: riprova!');
  				window.setTimeout(function(){
					$.ui.hideMask()},1000);
					return false}, options);
        }
    }
	
	$scope.viewUploadedPictures = function() {
		alert("cliccato vedi");
        server = "http://www.mimanchitu.it/public/phonegap/upload.php?nome=Amministratore";
        if (server) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState === 4){
                    if (xmlhttp.status === 200) {					 
				var img = document.getElementById('camera_image');
				var btnUp = document.getElementById('uploaded');
				btnUp.style.visibility = "visible";
                img.style.display = "none";
				btnUp.style.display = "none";
                document.getElementById('server_images').innerHTML = xmlhttp.responseText;
                    }
                    else {
                   $ionicLoading.show({template: 'Errore durante il caricamento...', duration: 1000});
					return false;
                    }
                }
            };
            xmlhttp.open("GET", server , true);
            xmlhttp.send();       	
        }	
    }
	
	$scope.viewPictures = function() {
		alert("cliccato vedi");
        server = "http://www.mimanchitu.it/public/phonegap/upload.php?nome=Amministratore";
        if (server) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState === 4){
                    if (xmlhttp.status === 200) {					 
                document.getElementById('server_images').innerHTML = xmlhttp.responseText;
                    }
                    else { $ionicLoading.show({template: 'Errore durante il caricamento...', duration: 1000});
					return false;
                    }
                }
            };
            xmlhttp.open("GET", server , true);
            xmlhttp.send()}	
    }
})

Wehen pherapse I click on button with ng-click=takePicture() the logcat give me this error:

ReferenceError: destinationType is not defined

It’s like cordova don’t give ondeviceready…

what’s wrong???