flowjs / ng-flow

Flow.js html5 file upload extension on angular.js framework
http://flowjs.github.io/ng-flow/
MIT License
1.38k stars 303 forks source link

Document smart ways for monitoring file upload progress in promise like fashion #361

Open evilaliv3 opened 2 years ago

evilaliv3 commented 2 years ago

I'm trying to implement monitoring of file upload completion in a promise like fashion and i consider that we miss proper documentaton for a functional and an efficient way to implement this.

This would be helpful for projects where the file upload is implemented within a form, where file uploads are set to start in pause state and the submit button is mapped to a trigger of file upload start that should then wait for file upload completion before performing submission completion.

The documentation should consider to clarify possibilities for efficiently waiting on a single flow object and on multiple flow objects.

evilaliv3 commented 2 years ago

@AidasK: Do you have by any chance any advice to implement this?

At the moment i'm evaluating that this could be only implemented by implementing a custom watch function with calls to the .progress() funcion to ensure the flow object / the multiple flow objects are in complete state.

Thank you for your support.

evilaliv3 commented 2 years ago

Here the current way i managed to check for this:


    $scope.interval = $interval(function() {
      for (key in $scope.uploads) {
        if ($scope.uploads[key] &&
            $scope.uploads[key].isUploading &&
            $scope.uploads[key].isUploading()) {
          return;
        }
      }

      $interval.cancel($scope.interval);

      // code to be executed when all the uploads have been completed

    }, 1000);
AidasK commented 2 years ago

Since we are using promises, we should use them instead of the intervals. Can't we check if promise has resolved and check isUploading variable there? Using intervals or timeouts just shows that library is not flexible enough or it's used incorrectly.