Skip to content

Instantly share code, notes, and snippets.

@dalibor
Created October 13, 2010 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalibor/623617 to your computer and use it in GitHub Desktop.
Save dalibor/623617 to your computer and use it in GitHub Desktop.
var currentMedia = false;
// Get photo
Ti.Media.showCamera({
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: function(event) {
var cropRect = event.cropRect;
currentMedia = event.media;
},
error:function(error) {
Ti.UI.createAlertDialog({title:'Camera problem', message:'Camera problem or device has no camera.'}).show();
},
allowImageEditing:true,
saveToPhotoGallery:false
});
// Send photo
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = xhrOnError;
xhr.onload = function() {
var json = JSON.parse(this.responseText);
if (json.status === "ok") {
showSuccess();
} else {
showError(json);
}
};
var data = {"_method": "PUT", "photo": currentMedia};
xhr.open('PUT', apiEndpoint + options.problem_id);
xhr.send(data);
# Rails backend
def update
@problem = Problem.find(params[:id])
@problem.photo = params[:photo]
@problem.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment