I am creating a cross platform app using PhoneGap and the Intel XDK. I am stuck on how to upload an image from the camera to my Azure Blob Storage. I am generating my SAS without an issue. The problem comes when I try to upload the image itself. I have a URL to the image (localhost) that I want to upload. I first tried to use the file upload utility provided by the XDK like so:
intel.xdk.file.uploadToServer(imageUrl,
azureUrl + info.resourceName + '?' + info.sasQueryString,
"",
"image/jpeg",
"updateUploadProgress");
That would start the upload progress (it seemed) and the updateUploadProgress would fire once. If I cut down the image quality and took a picture of just black (smallest size possible), it would get to 100% (otherwise it would get to a smaller percentage) but then nothing. The events that I registered for completion would not fire and I didn't see any error in debugging. My assumption was that it had something to do with the blob type or that it was using a POST instead of a PUT.
I next tried to use a straight XMLHttpRequest. After some configuration, I could get it to upload the output of a canvas object like so:
var canvas = document.createElement("canvas");
var imageObj = document.createElement('img');
imageObj.src = imageUrl;
canvas.width = imageObj.width;
canvas.height = imageObj.height;
var context = canvas.getContext('2d');
context.drawImage(imageObj, 0, 0);
xhr.send(canvas.toDataURL("image/jpeg").split(',')[1]);
The problem there is that it would upload a file of approximately the right size but it was corrupt. This method also doesn't work at all on the iPhone app, just the emulator. I believe there might be an issue using a straight XMLHttpRequest call with the XDK.
Any suggestions for how I can upload this file to Azure?