withCredentials: true }

时间:2022-06-01 08:41:53

// 上传文件地点 var uploadUrl = apiInterceptor.webApiHostUrl + ‘/test/Upload‘; // angularjs上传要领 $scope.upload = function() {if ($scope.file) { // 选中文件 importData(); } }; // 导入数据 var importData = function() { if (!$scope.file || !$scope.file.name) { SweetAlert.info(‘请选择文件‘); return; } // $q需要注入 var deferred = $q.defer(); var tempFileName = PWC.newGuid() + ‘.dat‘; var token = $(‘input[name="__RequestVerificationToken"]‘).val(); Upload.upload({ url: uploadUrl, data: { cancel: false, filename: $scope.file.name, }, file: $scope.file, resumeChunkSize: resumable ? $scope.chunkSize : null, headers: { ‘Access-Control-Allow-Origin‘: ‘*‘, Authorization: apiInterceptor.tokenType + ‘ ‘ + apiInterceptor.apiToken, __RequestVerificationToken: token, withCredentials: true }, __RequestVerificationToken: token, withCredentials: true }).then(function(resp) { var ret = resp.data; deferred.resolve(); }, function(resp) { deferred.resolve(); console.log(‘Error status: ‘ + resp.statusText); }, function(evt) { deferred.resolve(); var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); $log.debug(‘progress: ‘ + progressPercentage + ‘% ‘ + evt.config.data.file.name); }); };