Take picture from camera or gallery with cordova


#1

Hello I’m tryng to convert old app created with intel appframework to ionic framework.
In this app the user could take photo and upload from camera or gallery with this working code:

function takePicture() {
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;
$.ui.showMask(‘Scattata!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false
},
function(e) {
$.ui.showMask(‘Errore durante il caricamento!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false
},
{quality: 40, destinationType: destinationType.FILE_URI});
};

function selectPicture() {
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;
$.ui.showMask(‘Caricata!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false
},
function(e) {
$.ui.showMask(‘Errore di caricamento o immagine troppo grande!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false
},
{quality: 40, destinationType: destinationType.FILE_URI, sourceType: pictureSource.PHOTOLIBRARY});
};

function uploadPicture() {
var img = document.getElementById(‘camera_image’);
var imageURI = img.src;
if (!imageURI || (img.style.display == “none”)) {
$.ui.showMask(‘Scatta una foto o scegline una dalla galleria!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false}
server = “http://www.mimanchitu.it/public/phonegap/upload.php”;
if (server) {

    var options = new FileUploadOptions();
	$.ui.showMask("Sto caricando la foto: attendi qualche secondo...");
    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 = localStorage.getItem("nameStorage");
  	params.value2 = localStorage.getItem("idStorage");
  	options.params = params;
    // Transfer picture to server
    var ft = new FileTransfer();
    ft.upload(imageURI, server, function(r) {
		$.ui.showMask("Caricamento avvenuto: "+r.bytesSent+" bytes caricati.");
		window.setTimeout(function(){
			$.ui.hideMask()},1000);
			viewUploadedPictures();
			return false}, 
	
	function(error) {
		$.ui.showMask('Caricamento non riuscito: riprova!');
		window.setTimeout(function(){
			$.ui.hideMask()},1000);
			return false}, options);
}

}

function viewUploadedPictures() {
server = “http://www.mimanchitu.it/public/phonegap/upload.php?nome="+localStorage.getItem("nameStorage”);
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 {
$.ui.showMask(‘Errore durante il caricamento delle tue foto!’);
window.setTimeout(function(){$.ui.hideMask()},1000);
return false;
}
}
};
xmlhttp.open(“GET”, server , true);
xmlhttp.send();
}
}

function viewPictures() {
$.ui.showMask(‘Controllo le foto che hai già caricato…’);
server = “http://www.mimanchitu.it/public/phonegap/upload.php?nome="+localStorage.getItem("nameStorage”);
if (server) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState === 4){
if (xmlhttp.status === 200) {
document.getElementById(‘server_images’).innerHTML = xmlhttp.responseText;
$.ui.hideMask();
}
else {
$.ui.hideMask();
$.ui.showMask(‘Errore durante il caricamento delle tue foto!’);
window.setTimeout(function(){
$.ui.hideMask()},1000);
return false;
}
}
};
xmlhttp.open(“GET”, server , true);
xmlhttp.send()}
}

By changing only the jqeury code (like ui.hidemask etc.) do you think working on ionic app?