send the file to my asp.net webapi controller from angularjs -
am trying upload image file. need send file asp.net web api controller angularjs. tried several questions. (i dont know going wrong) wont me. can 1 me solve it.
html
<input type="file" file="file" fil onchange="angular.element(this).scope().photochanged(this.files)" /> <img ng-src="{{ thumbnail.dataurl }}"width="150" height="150" />
angular controller
//this preview uplaode image $scope.thumbnail = { dataurl: 'adsfas' }; $scope.filereadersupported = window.filereader != null; $scope.photochanged = function (files) { if (files != null) { var file = files[0]; if ($scope.filereadersupported && file.type.indexof('image') > -1) { $timeout(function () { var filereader = new filereader(); filereader.readasdataurl(file); filereader.onload = function (e) { $timeout(function () { $scope.thumbnail.dataurl = e.target.result; }); } }); } } }; //after button pressed $scope.addbanner = function () { var request = $http({ method: 'post', url: urls.api + 'banner/postbanner', data: data, contenttype: multipart/form-data; processdata: false, //data: json.stringify(dataobj) }).success(function (data, status) { alert('saved succesfully'); }) .error(function (error) { $scope.status = 'unable upload banner details : ' + error.message; console.log($scope.status); }); };
in opinion it's better use directive this. example: https://github.com/danialfarid/ng-file-upload . you'll progress reporting etc , cross-browser compatibility problems solved. no need invent wheel again here.
Comments
Post a Comment