angularJs上傳文件(非form上傳)
阿新 • • 發佈:2018-06-01
list amp success acs att ror tor 出了 end
angular.js:13920 Broken interceptor detected: Config object not supplied in rejection:
<input type="file" id="file{{$index}}" class="file" ngf-select ngf-change="cacScriptUploadVm.views.changeAttach($file,$index)">
function save() { console.log(vm.views.scriptList);var form = new FormData(); for (var i = 0; i < vm.views.scriptList.length; i++) { var file = angular.element(".file")[i].files[0]; form.append("files", file);//files和後臺接收字段名稱一樣 } //傳入出了file以外的實體 /* var scriptList = JSON.stringify(vm.views.scriptList); form.append("script", scriptList);*/ form.append("newDir","");//傳一個字符串 cacScriptService.uploadFile(form); } function changeAttach($file, $index) { if ($file != null && vm.views.scriptList.length > 0 && vm.views.scriptList.length >= $index) { vm.views.files[$index]= $file; } }
function uploadFile(form) { var url = _appconfig.apiBaseUrls.git + ‘/api/git/cac/upload‘; $http({ method: ‘POST‘, url: url, data: form, headers: {‘Content-Type‘: undefined}, transformRequest: angular.identity, transformResponse: function(data) { // 轉換response,這樣就能接收後臺傳回來String,默認接收是json。沒寫這個屬性之前,上傳成功後卻返回到error,而且會報上面的錯誤,寫了這個就不會 return data; } }).success(function (data) { console.log(‘upload success‘); }).error(function (data) { console.log(‘upload fail‘); }); }
angularJs上傳文件(非form上傳)