1

I need calculate the percentage of upload of a file in angularjs. I created a service to start the upload

mainApp.service('uploadFile', ['$http', function ($http) {
    this.uploadFileToUrl = function(files, uploadUrl, json, site, callback ){
        var fd = new FormData();

        angular.forEach(files, function(file) {
            fd.append('file', file);
            var pc = parseInt(100 - (file.loaded / file.total * 100));

            console.log(pc + "% 0");

        });

        fd.append('json', angular.toJson(json));
        fd.append('site', site);

        //console.log("fd "+  fd);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        })
        .success(callback, json.length=0)
        .error(callback);
    }
}]);

But when i try to stamp in the console the percentage i only get

NaN% 0

what is wrong here?

Atlas91
  • 5,754
  • 17
  • 69
  • 141

0 Answers0