Book Image

PhoneGap By Example

Book Image

PhoneGap By Example

Overview of this book

Table of Contents (17 chapters)
PhoneGap By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing file upload on the application side


To be able to upload files from our mobile Cordova application, we need to install an additional FileTransfer plugin:

$ cordova plugin add org.apache.cordova.file-transfer

Tip

This plugin allows you to upload and download files. This plugin defines global FileTransfer and FileUploadOptions constructors.

We will now change the savePhoto method in the Main.js controller:

if (Travelly.app.getSetting('token')) {
    self.savePhotoToService(picture, function(isSuccess, errorMessage) {
        setTimeout(function(){
            popup.hide();    
        },3000)
    });
} else {
    alert('Please login if you want to save picture online.');
}

Here, we checked whether we have the token stored in settings and called the self.savePhotoToService method if the token is present:

savePhotoToService: function(picture, callback) {
    var self = this,
        svcUrl = Travelly.app.getGlobal('svcUrl'),
        publishUrl = svcUrl + '/pictures?access_token=' + Travelly...