【问题标题】:How to track progress using eventHandlers and uploadEventHandlers in angularjs 1.5.5 with $http or $resource?如何使用 $http 或 $resource 在 angularjs 1.5.5 中使用 eventHandlers 和 uploadEventHandlers 跟踪进度?
【发布时间】:2016-11-08 17:20:47
【问题描述】:

我正在尝试严格遵守使用 $http 或 $resource 进行文件上传的 angularjs 代码。

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);
});

事件根本没有被触发。我错过了什么?

参考文献

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

【问题讨论】:

    标签: angularjs file-upload


    【解决方案1】:

    发布查询后找到它。感觉很傻。我不得不更新 bower 中的 angularjs 版本,以确保所有依赖项都解析为 angular 1.5.5 及更高版本。

    Reference for Details

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-20
      • 2016-10-28
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      相关资源
      最近更新 更多