Navjyot
Navjyot

Reputation: 118

File Upload with AngularJS and ASP.NET MVC

I am new to ASP.NET MVC and AngularJS, How can I Upload file (Image/PDF/Doc) to server Folder By AngularJS Controller with ASP.NET MVC Controller

Upvotes: 2

Views: 2220

Answers (1)

Leo Much
Leo Much

Reputation: 659

you can use the angular-file-upload first install it:

bower install bower install angular-file-upload

then add it as dependency in your app.

angular.module('your-app-name', ['angularFileUpload']);

In your controller, inject the FileUploader service:

angular.module('your-app-name').controller('ctrlName',
      ['$scope','FileUploader', function($scope, FileUploader) {
       $scope.uploader = new FileUploader({
                           url: 'server_url_here'
                   //you can add other configuration here like xsrf headers  
          });
      }]);

Then in your html:

               Multiple
                <input type="file" nv-file-select="" uploader="uploader" multiple  /><br/>

                Single
                <input type="file" nv-file-select="" uploader="uploader" />

You can find a detailed explanation here: https://github.com/nervgh/angular-file-upload An example: https://github.com/nervgh/angular-file-upload/tree/master/examples/simple

Upvotes: 3

Related Questions