Handling Images with ArrowDB in Titanium app

Posted By : Pawanpreet Singh | 29-Jun-2015

There are various times when we need to save a Photo in database, ArrowDB also provides us same to save the users uploaded image to server and if user needs it user can get the link of s3 which he/she can use in its app.

Here I will show you how to get from device and save it in ArrowDB

Getting Image from device


var mediaParams = {
	success : handlePhoto,
	cancel : function() {
     //do nothing
	},
	error : function(error) {
		 alert(error);
	},
	mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO
};
 
Titanium.Media.openPhotoGallery(mediaParams);

function handlePhoto(e){
  var file = Titanium.Filesystem.getFile(e.media.nativePath);
  sendPhoto(file);
}
 

Here we are selecting an image from gallery and opening then sending the selected image to sendPhoto which will send this selected image to the server and is shown below, but before using this user must be logged in before calling the photo api.

Saving Photo


function sendFile(file){
Cloud.Photos.create({
    photo: Titanium.Filesystem.getFile('photo.jpg')
}, 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)));
    }
});
}
 

Now the photo is stored ArrowDB, Its time to fetch for use in app

Fetching Photo

 Cloud.Photos.show({
    photo_id: PhotoIdWhichWasReturnedWhileSaving
}, function (e) {
    if (e.success) {
        var photo = e.photos[0];
        alert('Success:\n' +
            'url: ' + photo.url + '\n'
    } else {
        alert('Error:\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});
 

 

You can use this image url in your app to show this image.

THANKS

 

About Author

Author Image
Pawanpreet Singh

Pawanpreet is an seasoned Project Manager with a wealth of knowledge in software development, specializing in frontend and mobile applications. He possesses a strong command of project management tools, including Jira, Trello, and others. With a proven track record, he has successfully overseen the delivery of multiple software development projects, managing budgets and large teams. Notable projects he has contributed to include TimeForge, Yogyata, Kairos, Veto, Inspirien App, and more. Pawanpreet excels in developing and maintaining project plans, schedules, and budgets, ensuring timely delivery while staying within allocated resources. He collaborates closely with clients to define project scope and requirements, establish timelines and milestones, and effectively manage expectations. Regular project status meetings are conducted by him, providing clients and stakeholders with consistent updates on project progress, risks, and issues. Additionally, he coaches and mentors project leads, offering guidance on project management best practices and supporting their professional development.

Request for Proposal

Name is required

Comment is required

Sending message..