Hi I have a problem in project that I'm trying to upload the image in server through json. Actually i'm getting the image from gallery after getting the image from the gallery I'm converting the image into base64 format and i'm trying to upload in server . It's uploading in ios and when i'm trying to upload from android device the image is converting into base64 and the empty image is uploading in server. Here Is my code . can any one help me get out of this
var imageUrlvalue = " "; var imgStr = " "; $.submit.addEventListener('click', function(e) { var viewImg = Titanium.UI.createImageView({ top: '30%', height: '45%', bottom: '25%' }); Titanium.Media.openPhotoGallery({ success : function(e) { var testimages = "/images/p2.jpg"; var image = e.media; Titanium.API.info('image url: ' + e.media); //Ti.API.info(image.height +' x '+ image.width); var imageView = Titanium.UI.createImageView({ image:image, width:400, height:400 }); image1 = imageView.toImage().media; Ti.API.info(image1.height +" x "+ image1.width); imgStr=Ti.Utils.base64encode(image1).toString(); Titanium.API.info('image url: ' + imgStr); // Titanium.API.info('image url: ' + Ti.Utils.base64decode(imgStr)); }, cancel : function() { Ti.API.info('user cancelled galary.'); }, error : function(error) { var alert = Titanium.UI.createAlertDialog({ title : 'Sorry!', message : 'Error: ' + error.code }); alert.show(); }, mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO }); }); $.test.addEventListener('click', function(e) { submitImage(); }); function submitImage(){ var imgxhr = Titanium.Network.createHTTPClient(); imgxhr.setTimeout(35000); imgxhr.onload = function(e) { Titanium.API.info('connected: ' ); var imgparse = JSON.parse(this.responseText); imageUrlvalue = imgparse.url; Ti.API.info(' submitImage image parse: ' + imageUrlvalue); }; imgxhr.ondatastream = function(e) { Ti.API.info('ONDATASTREAM - PROGRESS: ' + e.progress); }; imgxhr.onerror = function(e) { //alert('image parse: wrong : '); alert("test :"+e.error); // alert( "status :"+this.status); // alert("error" + e.toString); }; var imgData = { profilepic : imgStr, }; Titanium.API.info(' post image url: ' + JSON.stringify(imgData)); imgxhr.open('POST','http://xxxxxxx/index.php?r=api/UploadProfile&profilepic='+imgStr); //xhr.setRequestHeader('Content-Type', "application/json; charset=utf-8"); imgxhr.setRequestHeader('enctype', 'multipart/form-data'); imgxhr.send(); }