Cordova file transfer messing with $scope update


#1

I’m using the file transfer plugin to upload files. Basically all the files do upload but I am also trying to include a little helper text to show the user the progress, ie. 1 of 3, 2 of 3, 3 of 3, then ‘Uploading completed’.

Below is the snippet of the code I am using,

The problem is I just see “Uploading image 1 of 3” and then nothing else. However the sendImage method is definitely called 3 times as the 3 images are uploaded to the server.

Also if I add any console.log message in the success callback for transfer.upload I only see the first set of the console.log message.

$scope.syncImages = function() {
    $scope.imageSyncMessage = 'Starting the uploading...';
    Database.getUnsyncedImages().then(function (images) {
        // images will be an array with 3 items
        sendImage(0, images);
    });
};

sendImage = function(image, images) {
    var count = image + 1;
    $scope.imageSyncMessage = 'Uploading image ' + count + ' of ' + images.length;
    var file = images[image];
    var transfer = new FileTransfer();
    transfer.upload(file.comment, encodeURI(...), function(data) {
        image++;
        if (image < images.length) {
            sendImage(image, images);
        }
        if (count == images.length) {
            $scope.imageSyncMessage = 'Uploading complete';
        }
    }, function(error) {
        var message = error.body;
    }, {
        fileKey: 'file',
        mimeType: 'image/jpeg',
        headers: {
            'X-Auth-Token': 'OGzi6hcd7r2KphNWBJg0SqwhTv1dgwSD'
        },
        chunkedMode: false,
    });
};

Below are the plugin versions I have:

cordova-plugin-file 2.1.0 "File"
cordova-plugin-file-transfer 1.2.0 "File Transfer"
cordova-plugin-network-information 1.0.0 "Network Information"
cordova-sqlite-storage 0.7.9 "Cordova sqlite storage plugin"
org.apache.cordova.camera 0.2.9 "Camera"
org.apache.cordova.console 0.2.8 "Console"
org.apache.cordova.device 0.2.9 "Device"