2016-07-06 57 views
0

我想嚴格遵守使用$ http或$資源做文件上傳的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

回答

3

發佈查詢後發現它。感覺愚蠢。我必須更新bower中的angularjs版本,以確保所有依賴項解析爲1.5.5及更高版本。

Reference for Details

相關問題