Skip to content

Commit

Permalink
Add progress event to file upload + download
Browse files Browse the repository at this point in the history
returns a notify promise for percentage progress
  • Loading branch information
pbernasconi committed Jun 9, 2014
1 parent c926317 commit 8dcdc93
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/plugins/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ angular.module('ngCordova.plugins.file', [])
var q = $q.defer();
var fileTransfer = new FileTransfer();
var uri = encodeURI(source);

fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
q.notify(perc);
}
};

fileTransfer.download(
uri,
Expand All @@ -160,12 +167,21 @@ angular.module('ngCordova.plugins.file', [])
q.reject(error);
},
trustAllHosts, options);

return q.promise;
},

uploadFile: function (server, filePath, options) {
var q = $q.defer();
var fileTransfer = new FileTransfer();
var uri = encodeURI(server);

fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
q.notify(perc);
}
};

fileTransfer.upload(
filePath,
Expand All @@ -177,6 +193,8 @@ angular.module('ngCordova.plugins.file', [])
q.reject(error);
},
options)

return q.promise
}

};
Expand Down

0 comments on commit 8dcdc93

Please sign in to comment.