This is working on the iPhone but for some reason with android the image uploads, it is the correct size but it is corrupted.
What i do below is take the photo, resize it using image factory (the image is fine after resize. Im looking at it on the phone) and then upload it to the server. Any ideas on whats going wrong?
tw.ui.takePhoto = function(vin){ Titanium.Media.showCamera({ success:function(event) { var cropRect = event.cropRect; var image = event.media; Ti.API.debug('Our type was: '+event.mediaType); if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { Ti.App.fireEvent('show_indicator'); var image = event.media var newImage = resizeKeepAspectRatioNewHeight(image, 1937, 1937, 500); var f = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,vin + '-' + currentPhotos + '.png'); f.write(newImage); var data_to_send = { "image": f.read(), "name": vin + '-' + currentPhotos + '.png' }; xhr = Ti.Network.createHTTPClient(); xhr.onsendstream = function(e) { if(!isAndroid){ var a = new Object; var progress = e.progress; progress = progress * 100 progress = parseInt(progress) a.title = 'Loading ' + progress + '%' ; Ti.App.fireEvent('change_title',a); } }; xhr.open("POST", siteurl + "app/uploadnew.html?name=" + vin + '-' + currentPhotos + '.png'); xhr.setRequestHeader("enctype", "multipart/form-data"); xhr.setRequestHeader("Content-Type", "image/png"); xhr.send(data_to_send); xhr.onload = function() { var response = JSON.parse(this.responseText) if(response.status == 'error'){ Ti.App.fireEvent('hide_indicator'); showError('Error',response.description); }else{ currentPhotos = currentPhotos + 1 lblPhotos.text = 'Photos Taken:' + currentPhotos; Ti.App.fireEvent('hide_indicator'); } }; } else { alert("got the wrong type back ="+event.mediaType); } }, cancel:function() { }, error:function(error) { // create alert var a = Titanium.UI.createAlertDialog({title:'Camera'}); // set message if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Please run this test on device'); } else { a.setMessage('Unexpected error: ' + error.code); } // show alert a.show(); }, saveToPhotoGallery:false, allowEditing:true, mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO] }); }
Your Answer
Think you can help? Login to answer this question!