How to track progress using eventHandlers and uplo

2019-01-20 06:55发布

I am trying to strictly adhere to angularjs code using $http or $resource to do file upload.

var uploadData = new FormData();
uploadData.append('file', obj.lfFile);
var fileData = angular.toJson({
    'FileName': obj.lfFile.name,
    'FileSize': obj.lfFile.size
});
uploadData.append('fileData', fileData)

$http({
    method: 'POST',
    url: vm.uploadPath,
    headers: {
        'Content-Type': undefined,
        'UserID': vm.folder.UserID,
        'ComputerID': vm.folder.ComputerID,
        'KeepCopyInCloud': vm.keepCopyInCloud,
        'OverWriteExistingFile': vm.overwriteExistingFile,
        'RootFileID': vm.folder.RootFileID,
        'FileName': obj.lfFile.name,
        'FileSize': obj.lfFile.size
    },
    eventHandlers: {
        progress: function(c) {
            console.log('Progress -> ' + c);
            console.log(c);
        }
    },
    uploadEventHandlers: {
        progress: function(e) {
            console.log('UploadProgress -> ' + e);
            console.log(e);
        }
    },
    data: uploadData,
    transformRequest: angular.identity
}).success(function(data) {
    console.log(data);
}).error(function(data, status) {
    console.log(data);
    console.log(status);
});

The events are not fired at all . What am i missing ?

References

  1. https://github.com/angular/angular.js/issues/14436
  2. https://github.com/angular/angular.js/pull/11547

1条回答
2楼-- · 2019-01-20 07:25

Found it after posting the query. Feeling stupid. I had to update the angularjs version in bower to ensure all dependencies resolve to angular 1.5.5 and above.

Reference for Details

查看更多
登录 后发表回答