AngularJS File upload with directive -


i use angularjs directive file upload , use directive way:

<input type="file" file-model="myfile">  

the directive looks this:

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('fileuploadservice', ['$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(){                 console.log('file upload successful');             })             .error(function() {                 console.log('file upload error');             });         }     }]); 

in controller:

$scope.uploadfile = function() {             var file = $scope.myfile;             if (typeof file != 'undefined' && file != null) {                 console.log('file ' + file);                 console.dir(file);                 var uploadurl = "/upload";                 fileupload.uploadfiletourl(file, uploadurl);             }         };     

the upload works fine. have 2 questions concerning improvements of upload:

  1. how upload more 1 file - there possibility upload more 1 file directive

  2. if file uploaded - how

  1. how upload more 1 file - there possibility upload more 1 file directive

you must set multipleon input field able select multiple files. then, file variable array of several files(if several files chosen) instead of file object.

  1. if file uploaded - how to

... ?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -