ngCordova file transfer progress update with promises

Hey team, I’m using ngCordova for file transfer and it’s working great. I do multiple file uploads with it using promises like so

 var promises=[];
 for(var i=0;i<photos.length;i++)
{
   $cordovaFileTransfer.upload(server, photos[i].uri, options)
 }

and then I use

 $q.all(promises).then(function(result) {
 // Success!
 }, function(err) {
  // Error
 }, function (progress) {
 // constant progress updates
});

Now there’s something very strange going on. If instead of using the above code for promises I do the upload for just a single file with the .then chained with the upload it works just fine and I get the progress but not when I use promises like above, in that case the progress callback never gets called. Can you please tell me what I might be doing wrong?

You need to track the progress of each promise individually.
–> like store the task length in a variable --> if a promise has finished --> decrease the counter.

I’m sorry how do I store the task length?

simply promises.length ?!

I think I wasn’t able to explain myself better. I want to get the percentage progress available from the ngCordova file upload callback but only in this case where I chain multiple uploads together

yeah and you need to calcluate it within every promise:

  1. build up your upload-promise array
  2. each upload-promise function listens to its progress
  3. you know your have promise.length tasks, which should reach 100% --> so on every progress update of an upload you can calculate the progress globally --> store the progress of every upload in your controller/service and everytime something changes --> set it.

When you say within promise you don’t mean the .then function right since that function marks the completion? So where is the within promise? I don’t know much about promises just simple things so if you could explain please.