Skip to content

Instantly share code, notes, and snippets.

@cashlo
Created August 12, 2011 04:04
Show Gist options
  • Save cashlo/1141428 to your computer and use it in GitHub Desktop.
Save cashlo/1141428 to your computer and use it in GitHub Desktop.
Image upload directly from camera using appcelerator for android/iPhone
Titanium.Media.showCamera({
allowEditing: true,
success: function(event) {
var image = event.media;
var pxhr = Titanium.Network.createHTTPClient();
pxhr.onerror = function() {
Ti.UI.createNotification({
message:'Upload failed, please try again.'
}).show();
}
pxhr.onload = function() {
Ti.UI.createNotification({
message:'Uploaded: ' + this.responseText
}).show();
};
pxhr.setTimeout('10000');
pxhr.open("POST","http://example.com/upload.php");
pxhr.send({file:image});
},
cancel: function() {
},
error: function(error) {
// create alert
var a = Titanium.UI.createAlertDialog({
title:'Camera'
});
// set message
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Device does not have video recording capabilities');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment