Files Upload Using AngularJS In ASP.NET MVC And Bootstrap

Introduction

Multiple files uploaded with AngularJS and ASP.NET MVC scan an  individual file's upload progress. Files upload faster compared to the traditional way, which we followed earlier in ASP.NET.

Description

Here, I have an upload button. This one supports and lets the user select multiple files to upload and each file will be tracked, which is based on its upload progress. Here, you can check your file name, path, Extension, Size and status. Status message is based on the file upload to the destination or not.

This part is configured in AngularJS.

References for better understanding are given below.

  • http://www.c-sharpcorner.com/article/introduction-to-angularjs-in-asp-net-mvc/
  • http://www.c-sharpcorner.com/members/satyaprakash-samantaray
Steps to be followed are given below.

Step1

First, create a MVC Application named SatyaFileUploadAngularJS.

MVC

Step2

Create a folder named App_Content.

Inside it, add Bootstrap related files, as shown below.



Inside JS folder, create a sub folder named Practical.

Inside it, add two JavaScript files named ImageUploadMultipleController.js and Module.js.

Step 3

Code ref of ImageUploadMultipleController.js is given below.

  1. app.controller('ImageUploadMultipleCtrl'function ($scope) {  
  2.     $scope.fileList = [];  
  3.     $scope.curFile;  
  4.     $scope.ImageProperty = {  
  5.         file: ''  
  6.     }  
  7.     $scope.setFile = function (element) {  
  8.         $scope.fileList = [];  
  9.          
  10.         var files = element.files;  
  11.         for (var i = 0; i < files.length; i++) {  
  12.             $scope.ImageProperty.file = files[i];  
  13.   
  14.             $scope.fileList.push($scope.ImageProperty);  
  15.             $scope.ImageProperty = {};  
  16.             $scope.$apply();  
  17.         }  
  18.     }  
  19.     $scope.UploadFile = function () {  
  20.         for (var i = 0; i < $scope.fileList.length; i++) {  
  21.             $scope.UploadFileIndividual($scope.fileList[i].file,  
  22.                                         $scope.fileList[i].file.name,  
  23.                                         $scope.fileList[i].file.type,  
  24.                                         $scope.fileList[i].file.size,  
  25.                                         i);  
  26.         }  
  27.     }  
  28.     $scope.UploadFileIndividual = function (fileToUpload, name, type, size, index) {     
  29.         var reqObj = new XMLHttpRequest();  
  30.         reqObj.upload.addEventListener("progress", uploadProgress, false)  
  31.         reqObj.addEventListener("load", uploadComplete, false)  
  32.         reqObj.addEventListener("error", uploadFailed, false)  
  33.         reqObj.addEventListener("abort", uploadCanceled, false)  
  34.         reqObj.open("POST""/FileUpload/UploadFiles"true);  
  35.         reqObj.setRequestHeader("Content-Type""multipart/form-data");  
  36.         reqObj.setRequestHeader('X-File-Name', name);  
  37.         reqObj.setRequestHeader('X-File-Type', type);  
  38.         reqObj.setRequestHeader('X-File-Size', size);  
  39.         reqObj.send(fileToUpload);  
  40.         function uploadProgress(evt) {  
  41.             if (evt.lengthComputable) {  
  42.                 var uploadProgressCount = Math.round(evt.loaded * 100 / evt.total);  
  43.                 document.getElementById('P' + index).innerHTML = uploadProgressCount;  
  44.                 if (uploadProgressCount == 100) {  
  45.                     document.getElementById('P' + index).innerHTML =  
  46.                    '<i class="fa fa-refresh fa-spin" style="color:green;"></i>';  
  47.                 }  
  48.             }  
  49.         }  
  50.         function uploadComplete(evt) {            
  51.             document.getElementById('P' + index).innerHTML = '<span style="color:Green;font-weight:bold;font-style: oblique">Saved..</span>';  
  52.             $scope.NoOfFileSaved++;  
  53.             $scope.$apply();  
  54.         }  
  55.         function uploadFailed(evt) {  
  56.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Upload Failed..</span>';  
  57.         }  
  58.         function uploadCanceled(evt) {  
  59.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Canceled..</span>';  
  60.         }  
  61.     }  
  62. }); 
Code description

This part controls file upload progress and tracking of the files, using AngularJS.

The module to develop our Angular Controller is used for the file upload and the code is given below in an Angular Controller with SetFile function.

  1. $scope.setFile = function (element) {  
  2.         $scope.fileList = [];  
  3.   
  4. Now Get The Multiple files….  
  5.   
  6. var files = element.files;  
  7.         for (var i = 0; i < files.length; i++) {  
  8.             $scope.ImageProperty.file = files[i];  
  9.   
  10.             $scope.fileList.push($scope.ImageProperty);  
  11.             $scope.ImageProperty = {};  
  12.             $scope.$apply();  
  13.   
  14.         }   

Here, ImageUploadMultipleCtrl is our Controller name. The $scope variable fileList is an array of files, which you selected. This ends our step 1. Run the project and select the multiple files by pressing Ctrl key and you will find the effect given below.

The code given below is an Angular Controller with UploadFile function. Here, I have mentioned UploadFileIndividual Function with the assigned parameter, which is similar to the properties of the files.

  1. $scope.UploadFile = function () {  
  2.         for (var i = 0; i < $scope.fileList.length; i++) {  
  3.   
  4.             $scope.UploadFileIndividual($scope.fileList[i].file,  
  5.                                         $scope.fileList[i].file.name,  
  6.                                         $scope.fileList[i].file.type,  
  7.                                         $scope.fileList[i].file.size,  
  8.                                         i);  
  9.         }  
  10.   
  11.     } 
Parameters are like name, type/extension, size of the file.

I have developed an upload function with XMLHttpRequest. XMLHttpRequest is an API, which provides client functionality to transfer the data between a client and a Server. It provides an easy way to retrieve the data from a URL without having to do a full page refresh.

XMLHttpRequest was originally designed by Microsoft and is supported by Mozilla, Apple and Google.

I chose XMLHttpRequest for the reasons given below.

  1. It provides us asynchronous upload of the multiple files.
  2. It provides a way for tracking the progress of each file.

I have all the files in an array named fileList, so loop through the fileList and get each file from the list with the name, size, type and send all to another function to upload, so add two functions at our Controller at imageUploadMultipleController.js.

  1. UploadFile - This function calls when we click Upload button.
  2. UploadFileIndividual function has parameters like fileToUpload, name, type, size, index- It is responsible to upload an indivudual file. It takes 4 parameters; i.e., the file to upload, the file name, the file type, file size and an index.
  1. $scope.UploadFile = function () {  
  2.   
  3.         for (var i = 0; i < $scope.fileList.length; i++) {  
  4.   
  5.             $scope.UploadFileIndividual($scope.fileList[i].file,  
  6.                                         $scope.fileList[i].file.name,  
  7.                                         $scope.fileList[i].file.type,  
  8.                                         $scope.fileList[i].file.size,  
  9.                                         i);  
  10.         }  
  11.   
  12.     }  
  13.   
  14.   
  15. $scope.UploadFileIndividual = function (fileToUpload, name, type, size, index) {         
  16.         var reqObj = new XMLHttpRequest();   
  17.         reqObj.upload.addEventListener("progress", uploadProgress, false)  
  18.         reqObj.addEventListener("load", uploadComplete, false)  
  19.         reqObj.addEventListener("error", uploadFailed, false)  
  20.         reqObj.addEventListener("abort", uploadCanceled, false)  
  21.         reqObj.open("POST""/FileUpload/UploadFiles"true);  
  22.         reqObj.setRequestHeader("Content-Type""multipart/form-data");  
  23.         reqObj.setRequestHeader('X-File-Name', name);  
  24.         reqObj.setRequestHeader('X-File-Type', type);  
  25.         reqObj.setRequestHeader('X-File-Size', size);  
  26.         reqObj.send(fileToUpload);  
  27.         function uploadProgress(evt) {  
  28.             if (evt.lengthComputable) {  
  29.                 var uploadProgressCount = Math.round(evt.loaded * 100 / evt.total);  
  30.                 document.getElementById('P' + index).innerHTML = uploadProgressCount;  
  31.                 if (uploadProgressCount == 100) {  
  32.                     document.getElementById('P' + index).innerHTML =  
  33.                    '<i class="fa fa-refresh fa-spin" style="color:green;"></i>';  
  34.                 }  
  35.             }  
  36.         }  
  37.         function uploadComplete(evt) {         
  38.             document.getElementById('P' + index).innerHTML = '<span style="color:Green;font-weight:bold;font-style: oblique">Saved..</span>';  
  39.             $scope.NoOfFileSaved++;  
  40.             $scope.$apply();  
  41.         }  
  42.         function uploadFailed(evt) {  
  43.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Upload Failed..</span>';  
  44.         }  
  45.         function uploadCanceled(evt) {  
  46.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Canceled..</span>';  
  47.         }  
  48.     } 
Create XMLHttpRequest Object.
  1. var reqObj = new XMLHttpRequest(); 
The event Handler is defined below.
  1. reqObj.upload.addEventListener("progress", uploadProgress, false)  
  2.         reqObj.addEventListener("load", uploadComplete, false)  
  3.         reqObj.addEventListener("error", uploadFailed, false)  
  4.         reqObj.addEventListener("abort", uploadCanceled, false
Open the object and set method of call : get/post, url to call, isasynchronous : true/False.
  1. reqObj.open("POST""/FileUpload/UploadFiles"true); 
Set Content-Type at request header. For file upload, it's value must be multipart/form-data.
  1. reqObj.setRequestHeader("Content-Type""multipart/form-data"); 
Set other header like file name, size and type.
  1. reqObj.setRequestHeader('X-File-Name', name);  
  2. reqObj.setRequestHeader('X-File-Type', type);  
  3. reqObj.setRequestHeader('X-File-Size', size); 
Send the file.
  1. reqObj.send(fileToUpload); 
The command given below catches the progress event and pass it to our own function named uploadProgress.
  1. function uploadProgress(evt) {  
  2.     if (evt.lengthComputable) {  
  3.   
  4.         var uploadProgressCount = Math.round(evt.loaded * 100 / evt.total);  
  5.   
  6.         document.getElementById('P' + index).innerHTML = uploadProgressCount;  
  7.   
  8.         if (uploadProgressCount == 100) {  
  9.             document.getElementById('P' + index).innerHTML =  
  10.            '<i class="fa fa-refresh fa-spin" style="color:green;"></i>';  
  11.         }  
  12.   
  13.     }  

In uploadProgress function, I have mentioned color of the progress control. When upload completes, then it shows a Spinner icon until the Server sends back a response.
  1. if (uploadProgressCount == 100) {  
  2.                     document.getElementById('P' + index).innerHTML =  
  3.                    '<i class="fa fa-refresh fa-spin" style="color:green;"></i>';  
  4.                 } 
The events mentioned below are raised when the Server sends back a response.

To Save status with the color, proceed, as shown below.

  1. function uploadComplete(evt) {  
  2.             document.getElementById('P' + index).innerHTML = '<span style="color:Green;font-weight:bold;font-style: oblique">Saved..</span>';  
  3.             $scope.NoOfFileSaved++;  
  4.             $scope.$apply();  
  5.         } 
For Upload Failed status with color, proceed, as shown below.
  1. function uploadFailed(evt) {  
  2.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Upload Failed..</span>';  
  3.         } 
 For Canceled status with color, proceed, as shown below.
  1. function uploadCanceled(evt) {  
  2.   
  3.             document.getElementById('P' + index).innerHTML = '<span style="color:Red;font-weight:bold;font-style: oblique">Canceled..</span>';  
  4.         }   

XMLHttpRequest object returns the status of an each event of each file. By writing an event handler function, we can access return status. We can add EventListener method of XMLHttpRequest object to handle the event . XMLHttpRequest raises an event at the different status of uploading.

  1. Progress - It is raised during the upload process and sends us the necessary information on the progress status.
  2. Load - It is raised after the uploaded file is saved at the destination and the Server sends back a response.
  3. Error - it raises imediately, if any error occurs during the upload.
  4. Abort - It raises imediately, if the user cancels the upload process.

The code mentioned above described how to develop an Upload functionality with XMLHttpRequest.

 
Step 4 
 
Code ref of Module.js
  1. var app = angular.module('AgApp', []);  
Code description

Now, use the module to develop Angular Controller for the file upload.

 
 
Step5

Create a controller class file named FileUploadController.cs.

ASP.NET MVC Controller helps to receive the object sent by XMLHttpRequest.

Code ref of FileUploadController.cs

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Mvc;  
  7.   
  8. namespace SatyaFileUploadAngularJS.Controllers  
  9. {  
  10.     public class FileUploadController : Controller  
  11.     {        
  12.         public ActionResult UploadMultipleFile()  
  13.         {  
  14.             return View();  
  15.         }  
  16.   
  17.         [HttpPost]  
  18.         public virtual string UploadFiles(object obj)  
  19.         {  
  20.   
  21.             var length = Request.ContentLength;  
  22.             var bytes = new byte[length];  
  23.             Request.InputStream.Read(bytes, 0, length);  
  24.   
  25.             var fileName = Request.Headers["X-File-Name"];  
  26.             var fileSize = Request.Headers["X-File-Size"];  
  27.             var fileType = Request.Headers["X-File-Type"];  
  28.   
  29.             var saveToFileLoc = "D:\\Images\\" + fileName;         
  30.             var fileStream = new FileStream(saveToFileLoc, FileMode.Create, FileAccess.ReadWrite);  
  31.             fileStream.Write(bytes, 0, length);  
  32.             fileStream.Close();  
  33.   
  34.             return string.Format("{0} bytes uploaded", bytes.Length);  
  35.         }  
  36.     }  

Code description

Here, I assigned the code to add headers.

  1. var fileName = Request.Headers["X-File-Name"];  
  2. var fileSize = Request.Headers["X-File-Size"];  
  3. var fileType = Request.Headers["X-File-Type"]; 
The uploaded file path is given below.
  1. var saveToFileLoc = "D:\\Images\\" + fileName; 
Save file functionality is written here.
  1. var fileStream = new FileStream(saveToFileLoc, FileMode.Create, FileAccess.ReadWrite);  
  2.             fileStream.Write(bytes, 0, length);  
  3.             fileStream.Close();  
  4.   
  5.             return string.Format("{0} bytes uploaded", bytes.Length); 
 
 
Step 6

Create a view named UploadMultipleFile.cshtml.

I used HTML input tag, using ASP.NET MVC to input multiple/ single file upload.

Code ref

  1. <html ng-app="AgApp">  
  2. <head>  
  3.     <meta name="viewport" content="width=device-width" />  
  4.     <title>Satyaprakash File Upload AngularJS</title>  
  5.     <link href="~/App_Content/CSS/bootstrap.min.css" rel="stylesheet" />  
  6.     <link href="~/App_Content/CSS/font-awesome.min.css" rel="stylesheet" />  
  7.     <style>  
  8.         table {  
  9.             font-family: arial, sans-serif;  
  10.             border-collapse: collapse;  
  11.             width: 100%;  
  12.         }  
  13.         td, th {  
  14.             border: 1px solid #dddddd;  
  15.             text-align: left;  
  16.             padding: 8px;  
  17.         }  
  18.         tr:nth-child(even) {  
  19.             background-color: #dddddd;  
  20.         }  
  21.         .button {  
  22.             background-color: #4CAF50;  
  23.             border: none;  
  24.             color: white;  
  25.             padding: 15px 32px;  
  26.             text-align: center;  
  27.             text-decoration: none;  
  28.             display: inline-block;  
  29.             font-size: 16px;  
  30.             margin: 4px 2px;  
  31.             cursor: pointer;  
  32.         }  
  33.         .button4 {  
  34.             border-radius: 9px;  
  35.         }  
  36.     </style>  
  37. </head>  
  38. <body>  
  39.     <h2 style="background-color: Yellow;color: Blue; text-align: center; font-style: oblique">Satya's File Upload using AngularJS</h2>  
  40.     <fieldset>  
  41.         <legend style="font-family:Arial Black;color:blue">Upload Multiple Files Here</legend>  
  42.         <div ng-controller="ImageUploadMultipleCtrl">  
  43.             <div class="col-md-12" style="text-align:center;margin-bottom:10px;">  
  44.                 <input type="file" id="file" name="file" multiple onchange="angular.element(this).scope().setFile(this)" accept="image/*" class="btn btn-primary" />  
  45.             </div>  
  46.             <div class="col-md-12">  
  47.                 <button ng-click="UploadFile()" class="button button4">Upload</button>  
  48.             </div>  
  49.             <div class="col-md-12" style="padding-top:10px;">  
  50.                 <div class="col-md-7">  
  51.                     <table align="center" border="1" cellpadding="4" cellspacing="4">  
  52.                         <thead>  
  53.                             <tr>  
  54.                                 <th style="background-color: Yellow;color: blue">File Name</th>  
  55.                                 <th style="background-color: Yellow;color: blue">File Type</th>  
  56.                                 <th style="background-color: Yellow;color: blue">File Size</th>  
  57.                                 <th style="background-color: Yellow;color: blue">Status</th>  
  58.                             </tr>  
  59.                         </thead>  
  60.                         <tbody>  
  61.                             <tr ng-repeat="file in fileList">  
  62.                                 <td style="color: blue">{{file.file.name}}</td>  
  63.                                 <td style="color: blue">{{file.file.type}}</td>  
  64.                                 <td style="color: blue">{{file.file.size}}</td>  
  65.                                 <td>  
  66.                                     <div id="{{'P'+$index}}">  
  67.                                     </div>  
  68.                                 </td>  
  69.                             </tr>  
  70.                         </tbody>  
  71.                     </table>  
  72.                 </div>  
  73.             </div>  
  74.         </div>         
  75.         <script src="~/App_Content/JS/jquery-1.7.2.min.js"></script>  
  76.         <script src="~/App_Content/JS/jquery.unobtrusive-ajax.min.js"></script>         
  77.         <script src="~/App_Content/JS/angular.min.js"></script>        
  78.         <script src="~/App_Content/JS/Practical/Module.js"></script>         
  79.         <script src="~/App_Content/JS/Practical/ImageUploadMultipleController.js"></script>  
  80.     </fieldset>  
  81.     <br />  
  82.     <br />  
  83.     <footer>  
  84.         <p style="background-color: Yellow; font-weight: bold; color:blue; text-align: center; font-style: oblique">© @DateTime.Now.ToLocalTime()</p> @*Add Date Time*@  
  85.     </footer>  
  86. </body>  
  87. </html> 
Code description
  • ng‐app="AgApp" we bootstrap an Angular Application.
  • ng‐controller="ImageUploadMultipleCtrl" specifies the Controller for this page, which contains the code to show the selected file information and file upload function. 
  1. <input type="file" id="file" name="file" multiple onchange="angular.element(this).scope().setFile(this)" accept="image/*" class="btn btn-primary" />  
  • This enables us to input the multiple files and onchange event, we call setFile function, which is an Angular function. This function collects all the files, which you selected and put into a $scope variable name fileList.
  • We loop through the fileList by <tr ng‐repeat="file in fileList"> to show the file information.
  • Each file has 3 auto property names, types and sizes. Thes 3 properties of files can be accessed directly.

I have added Bootstrap related files here.

  1. <link href="~/App_Content/CSS/bootstrap.min.css" rel="stylesheet" />  
  2. <link href="~/App_Content/CSS/font-awesome.min.css" rel="stylesheet" /> 
I have added style to Button and table control.
  1. <style>  
  2.         table {  
  3.             font-familyarialsans-serif;  
  4.             border-collapsecollapse;  
  5.             width100%;  
  6.         }  
  7.   
  8.         td, th {  
  9.             border1px solid #dddddd;  
  10.             text-alignleft;  
  11.             padding8px;  
  12.         }  
  13.   
  14.         tr:nth-child(even) {  
  15.             background-color#dddddd;  
  16.         }  
  17.   
  18.         .button {  
  19.             background-color#4CAF50;  
  20.             bordernone;  
  21.             colorwhite;  
  22.             padding15px 32px;  
  23.             text-aligncenter;  
  24.             text-decorationnone;  
  25.             display: inline-block;  
  26.             font-size16px;  
  27.             margin4px 2px;  
  28.             cursorpointer;  
  29.         }  
  30.   
  31.         .button4 {  
  32.             border-radius: 9px;  
  33.         }  
  34.     </style>   
For loading jQuery, proceed, as shown below.
  1. <script src="~/App_Content/JS/jquery-1.7.2.min.js"></script>  
  2. <script src="~/App_Content/JS/jquery.unobtrusive-ajax.min.js"></script> 
Loading Angular JS i
  1. <script src="~/App_Content/JS/angular.min.js"></script> 
Load our Angular Application 
  1. <script src="~/App_Content/JS/Practical/Module.js"></script> 
Load the page Controller
  1. <script src="~/App_Content/JS/Practical/ImageUploadMultipleController.js"></script> 
Proceed, as shown below.
  1. <div class="col-md-12" style="text-align:center;margin-bottom:10px;">  
  2.                 <input type="file" id="file" name="file" multiple onchange="angular.element(this).scope().setFile(this)" accept="image/*" class="btn btn-primary" />  
  3.             </div>   
I added the code for the button to upload the files and save it in the destination directory.
  1. <div class="col-md-12">  
  2.                 <button ng-click="UploadFile()" class="button button4">Upload</button>  
  3.             </div> 
I added for the table headers.
  1. <th style="background-color: Yellow;color: blue">File Name</th>  
  2. <th style="background-color: Yellow;color: blue">File Type</th>  
  3. <th style="background-color: Yellow;color: blue">File Size</th>  
  4. <th style="background-color: Yellow;color: blue">Status</th> 
I added for the header data, which is based on selected file properties. 
  1. <tr ng-repeat="file in fileList">  
  2.                                 <td style="color: blue">{{file.file.name}}</td>  
  3.                                 <td style="color: blue">{{file.file.type}}</td>  
  4.                                 <td style="color: blue">{{file.file.size}}</td>  
  5.                                 <td>  
  6.                                     <div id="{{'P'+$index}}">  
  7.                                     </div>  
  8.                                 </td>  
  9.                             </tr> 
The status part will show file progress count and the status of the uploaded file.
  1. <td>  
  2.   <div id="{{'P'+$index}}">  
  3.   
  4.   </div>  
  5. </td> 
 
 
Step7

Add the code for Web.Config file.

Change the Maximum Upload length in Web.config. In <system.web> section, change the http in the way given below.

Code ref

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <configuration>  
  3.   <appSettings>  
  4.     <add key="webpages:Version" value="3.0.0.0" />  
  5.     <add key="webpages:Enabled" value="false" />  
  6.     <add key="ClientValidationEnabled" value="true" />  
  7.     <add key="UnobtrusiveJavaScriptEnabled" value="true" />  
  8.   </appSettings>  
  9.   <system.web>  
  10.     <compilation debug="true" targetFramework="4.5" />  
  11.     <httpRuntime targetFramework="4.5" maxRequestLength="1048576" />  
  12.   </system.web>  
  13.   <system.webServer>  
  14.     <security>  
  15.       <requestFiltering>  
  16.         <requestLimits maxAllowedContentLength="1073741824" />  
  17.       </requestFiltering>  
  18.     </security>  
  19.   </system.webServer>  
  20. </configuration> 
Code description

In <system.web> section, change the http in the way given below.

  1. <httpRuntime targetFramework="4.5" maxRequestLength="1048576" /> 
Add/Update <system.webServer> section in the way given below.
  1. <system.webServer>  
  2.     <security>  
  3.       <requestFiltering>  
  4.         <requestLimits maxAllowedContentLength="1073741824" />  
  5.       </requestFiltering>  
  6.     </security>  
  7.   </system.webServer> 
NOTE

The value maxRequestLength in <system.web> and maxAllowedContentLength in <system.webserver> must be same.
 
 
 
Step 8

Set start page in MVC, using Controller name and controller action method.

Code ref of RouteConfig.cs

  1. routes.MapRoute(  
  2.                 name: "Default",  
  3.                 url: "{controller}/{action}/{id}",  
  4.                 defaults: new { controller = "FileUpload", action = "UploadMultipleFile", id = UrlParameter.Optional }  
  5.             ); 
Code description

The controller name - “FileUpload”.

The controller action method name - “UploadMultipleFile”.



OUTPUT

URL is - http://localhost:51235/FileUpload/UploadMultipleFile

Desktop View

 
 
By clicking Ctrl Key, select multiple files.
 


 

I uploaded the files by changing an invalid destination path i.e. D:\Images1
 

Refer the screenshot.



Progress bar is given

 

Mobile View

 
GIF images for better understanding.

Desktop View

 

Mobile View

  

Summary

  1. File upload, using AngularJS.
  2. Implement in MVC and Bootstrap.
  3. File progress tracking .
  4. AngularJS file upload is faster .

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now