Created
April 9, 2014 01:51
-
-
Save heyMP/10218319 to your computer and use it in GitHub Desktop.
Upload photo to Drupal Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PHOTOS Upload | |
var imagesrc; | |
function takePhoto() { | |
navigator.camera.getPicture(onSuccess, onFail, { quality: 30, destinationType: Camera.DestinationType.DATA_URL, correctOrientation:true }); | |
} | |
function onSuccess(imageData) { | |
var image = document.getElementById('photo-deposit'); | |
imagesrc = imageData; | |
uploadthePhoto(); | |
} | |
function onFail(message) { | |
alert('Failed because: ' + message); | |
$.mobile.hidePageLoadingMsg();// show loading message | |
} | |
function uploadthePhoto() { | |
newImageSrc = imagesrc; | |
$.mobile.showPageLoadingMsg();// show loading message | |
$.ajax({// upload the picture | |
url: 'http://keystone.niswebsolutions.com/api/file.json', | |
type: 'POST', | |
data: '{"uid":"1","filesize":"99999","filename":"work-order-photo.jpg","file":"'+newImageSrc+'"}', | |
dataType: 'json', | |
contentType: 'application/json', | |
error: function (XMLHttpRequest, textStatus, errorThrown) { | |
$.mobile.hidePageLoadingMsg();// show loading message | |
alert('Failed'); | |
console.log(JSON.stringify(XMLHttpRequest)); | |
console.log(JSON.stringify(textStatus)); | |
console.log(JSON.stringify(errorThrown)); | |
}, | |
success: function (data) { | |
console.log(JSON.stringify(data)); | |
var fid = data.fid; | |
$.ajax({// get node info | |
url: 'http://keystone.niswebsolutions.com/api/node.json', | |
type: 'POST', | |
data: '{"title":"Work Order Picture","type":"work_order_picture","field_image_picture":{"und":[{"fid":'+fid+'}]},"field_work_order_reference":{"und":[{"nid":"[nid:'+nid+']"}]},"uid":"1","language":"und"}', | |
dataType: 'json', | |
contentType: 'application/json', | |
error: function (XMLHttpRequest, textStatus, errorThrown) { | |
$.mobile.hidePageLoadingMsg();// show loading message | |
alert('Failed'); | |
console.log(JSON.stringify(XMLHttpRequest)); | |
console.log(JSON.stringify(textStatus)); | |
console.log(JSON.stringify(errorThrown)); | |
}, | |
success: function (data) { | |
$.mobile.changePage($("#page_node_pictures"), {allowSamePageTransition:true}); | |
$.mobile.hidePageLoadingMsg();// show loading message | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment