spring mvc - how to upload multiple files with form data to database using angularjs -
this code uploading file nwant upload multiple files form data @ same time using spring mvc,please me how using spring , angularjs
http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
<div ng-controller = "myctrl"> <input type = "file" file-model = "myfile"/> <button ng-click = "uploadfile()">upload me</button> </div> <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; 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(); fd.append('file', file); $http.post(uploadurl, fd, { transformrequest: angular.identity, headers: {'content-type': undefined} }) .success(function(){ }) .error(function(){ }); } }]); myapp.controller('myctrl', ['$scope', 'fileupload', function($scope, fileupload){ $scope.uploadfile = function(){ var file = $scope.myfile; console.log('file ' ); console.dir(file); var uploadurl = "http://localhost:8080/hbdatabase/static/image"; fileupload.uploadfiletourl(file, uploadurl); }; }]); </script>
Comments
Post a Comment