0
Сегодня у меня проблемы с загрузкой загруженного файла в вызов API. Я понятия не имею об этом.Загрузите файлы excel angularjs и получите проблемы с API SOA
Любой может сказать мне, как его решить?
My Существующих AngularJs является
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<script src="https://code.angularjs.org/1.3.0-rc.2/angular.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.directive('fileModel', ['$parse',
function ($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
debugger;
element.bind('change', function() {
scope.$apply(function() {
modelSetter(scope, element[0].files[0]);
});
});
}
};
}
]);
myApp.service('fileUpload', ['$http',
function ($http) {
this.uploadFileToUrl = function (file, uploadUrl) {
var fd = new FormData();
debugger;
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined
}
})
.success(function (resp) {
debugger;
})
.error(function (resp) {
debugger;
});
}
}
]);
myApp.controller('myCtrl', ['$scope', 'fileUpload',
function ($scope, fileUpload) {
debugger;
$scope.uploadFile = function() {
var file = $scope.myFile;
debugger;
//alert(JSON.stringify($scope.myFile));
//console.log('file is ' + JSON.stringify(file));
var uploadUrl = "http://localhost:56110/Api/Setting/fileUpload/1";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
}
]);
</script>
</head>
<body>
<div ng-controller="myCtrl">
<input type="file" file-model="myFile" />
<button ng-click="uploadFile()">upload me</button>
</div>
</body>
</html>
Код АФИ
// POST апи/установка общественности недействительным FileUpload ([FormData] значение UploadExcel, внутр идентификатор) { }
Мои выпуски
Это может помочь вам пример plnk https://lnkd.in/ewapdz3 –