I am trying to upload the picture that I take from camera to a rest service using HTTP Post method. I want to send the image as a blob. However when I use the following code to upload image,the image that gets on server is either empty or corrupted. Can someone please take a look at this code to see if this is the right way of sending blob over HTTP:
function openCamera(win) { //open camera if (Titanium.Media.isCameraSupported) { Titanium.Media.showCamera({ success : function(e) { win.ImageView.setImage(e.media); var bl = win.ImageView.toImage(); addPhoto(bl); //addPhoto('../images/GPS.png'); }, error : function(e) { Ti.UI.createAlertDialog({ title : 'Error', message : 'There was an error in taking picture' }).show(); }, cancel : function(e) { }, allowEditing : true, saveToPhotoGallery : false, mediaTypes : [Titanium.Media.MEDIA_TYPE_PHOTO] }) } } function addPhoto(image) { var format = 'json'; xhr = Titanium.Network.createHTTPClient(); xhr.timeout = 60000; xhr.onload = function() { }; var url = 'https://api.parse.com/1/files/pic7.jpg'; xhr.open('POST', url); xhr.setRequestHeader('X-Parse-Application-Id', 'Q6EX'); xhr.setRequestHeader('X-Parse-REST-API-Key', 'yJ8C617'); xhr.setRequestHeader("Content-Type", "image/jpeg"); xhr.send(image); }Thanks
1 Answer
I'm not really sure, but shouldn't you send your imagedata as a param of the POST request?
Like so: xhr.send({imgData: image});
Your Answer
Think you can help? Login to answer this question!