I have a function like this:
$scope.fileUpload = function (files) {
angular.forEach(files, function () {
var fd = new FormData();
fd.append('files[]', files[0]);
$http.post('/my-url', fd, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined}
}).then(function (data) {
console.log(data);
});
});
};
and template:
<input type="file"
name="files[]"
id="fileUploaderButton_contentFormFiles"
onchange="angular.element(this).scope().fileUpload(files)"
multiple>
<div class="progress" id="fileUploaderProgressbar_contentFormFiles">
<div class="progress-bar progress-bar-striped active"
role="progressbar"
aria-valuenow="{{progress}}"
aria-valuemin="0"
aria-valuemax="100"
style="min-width: 2em; width: {{progress}}%">
<span>{{progress}}%</span>
</div>
</div>
How can I $watch for for transferred value (bytes) of an uploading file so I can update {{progress}} in the progress bar during $http request (using native angular features)? Thanks in advance.