Skip to content

Instantly share code, notes, and snippets.

@grantges
Created November 26, 2012 22:18
Show Gist options
  • Save grantges/2c2e09b4ba82dbc001f0 to your computer and use it in GitHub Desktop.
Save grantges/2c2e09b4ba82dbc001f0 to your computer and use it in GitHub Desktop.
Quick function to upload photos taken from your camera to the cloud
function uploadPhoto( _source, _callback) {
var onSuccess = function(e){
if(e.media){
Cloud.Photos.create({
photo: e.media
}, function (e) {
if (e.success) {
var photo = e.photos[0];
alert('Success:\\n' +
'id: ' + photo.id + '\\n' +
'filename: ' + photo.filename + '\\n' +
'size: ' + photo.size,
'updated_at: ' + photo.updated_at);
} else {
alert('Error:\\n' +
((e.error && e.message) || JSON.stringify(e)));
}
_callback && _callback(e);
});
}
}
switch(_source){
case "CAMERA":
Ti.Media.showCamera({
animated: true,
allowEditing: true,
autohide: true,
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: onSuccess,
error: function(e){ alert('Error:\\n' +
((e.error && e.message) || JSON.stringify(e)));}
});
break;
case "GALLERY":
Ti.Media.openPhotoGallery({
animated: true,
allowEditing: true,
autohide: true,
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: onSuccess,
error: function(e){ alert('Error:\\n' +
((e.error && e.message) || JSON.stringify(e)));}
});
break;
default:
}
}
//Get a Photo from the users Photo Albums
uploadPhoto("GALLERY", function(e){
Ti.API.info("PHOTO UPLOAD STATUS: "+ e.success);
});
//Capture a Photo from the phone's camera
uploadPhoto("CAMERA", function(e){
Ti.API.info("PHOTO UPLOAD STATUS: "+ e.success);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment