Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm using angular-file-upload available here: https://github.com/danialfarid/angular-file-upload. As you can see in the example furnished on the same page, file data is posted to backend from a controller using the directives made available.

When I implemented the code however I moved the file posting to a service as that would allow me to re-use the functionality & feels the correct way(disagree?). Everything works fine except that I'm unable to figure out how to send the data from the .progress(function(evt)){}... function that tracks file upload completion status to the controller and respectively echo it on the html page.

Using the .then I can get the final success response I guess but how about this progress data?

Am I missing something very simple here? How to get this done?

share|improve this question
up vote 0 down vote accepted

After a longtime, here is how this would work.

Using the notify callback for the promise solves the problem. As I had stated earlier, I had moved the file upload code (based on this rep enter link description here) into the angular services and I was not able to get file upload progress. Since I was returning the promise from services, so I could only get the file completion.

the above git rep also has a

.progress(function(evt){ file_upload_percent=(parseInt(100.0 * evt.loaded / evt.total)})

function that gives the file completion percentage. Using the promise notify here, we can return this intermediate value like this :

.progress(function(evt) {   file_upload_percent=(parseInt(100.0 * evt.loaded / evt.total)); deferred.notify(file_upload_percent);})

later using notify callback from the promise return, we can access the file completion percentage.

.then(function(response){},function(){},function(update){$scope.file_upload_percent=update});

use $scope.file_upload_percent as you would wish to.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.