PDA

View Full Version : Uploading camera Image to server



smj
30 Aug 2011, 3:01 AM
Hello All,
I am working on a project where I need to change user picture so I am using phonegap to get Image from camera it's working now I have image data but how I will upload this image data to server.
Please help me..


Thank You

Code I am using

onPhotoDataSuccess = function (imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
imgData = imageData;
smallImage.src = "data:image/jpeg;base64," + imgData;

}

uploadimagefile = function(){
//Upload image
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName= "test";
options.mimeType="image/jpeg";

var params = new Object();
params.type = "patient";
params.owner_id = "120";

options.params = params;

var ft = new FileTransfer();
ft.upload(imageURI, "http://twork.docurehab.com/index.php/basic/image_upload", win, fail, options);

//Upload image using ajax
Ext.Ajax.request({
url:'http://twork.docurehab.com/index.php/basic/image_upload'
, params: {
type : 'patient'
, owner_id : '120'
, image_file : "data:image/jpeg;base64,"+imgData
}
, scope: this
, success: function(res){
//Ext.Msg.alert('Error', 'Working.' + res);
var r = Ext.decode(res.responseText);
/*if(r.success){
window.location.reload();
//Ext.getCmp('maincard').changeLayout(1);
}else{*/
Ext.Msg.alert('Error', r.message);
//}
}
, failure:function(res){
// Ext.Msg.alert('Error', 'Error in connection.');
}
})
}

Note: Only one of the above uploading code I am using but both are not working....