danywarner danywarner - 4 months ago 11x
Ajax Question

Upload a photo to web service with phonegap

OK, So I am able to take a picture with the phone's camera and view it inside an img, now I want to upload it through a web service that receives a

<File> base64Binary </File>.

This is how I set the image:

function onPhotoDataSuccess(imageData)
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;

And this is how I try to send it:

var ima=document.getElementById("smallImage").src;

var soapRequest ='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
'<InsertFileInfo xmlns="http://tempuri.org/">'+



type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError

function processSuccess(data, status, req)

if (status == "success")


function processError(data, status, req)
//alert(req.responseText + " " + status);

Then some minutes pass and I finally get the processError function message.

Can someone tell me what is wrong with this?


I got to solve it. If anyone has this issue: the variable 'ima' was requesting for the .src of an img but that didn't work. So I used something else to store the base64 value of the picture:

window.localStorage.setItem("CodePhoto", imageData);

And I read it inside the request like this:

var codePhoto = window.localStorage.getItem("CodigoFoto");

And Finally put it inside the


like this: