i am trying to upload multiple file using Angularjs and webapi.. This is my html table:
<body ng-app="fupApp">
<div ng-controller="fupController">
<input type="file" id="file" name="file" multiple
onchange="angular.element(this).scope().getFileDetails(this)" />
<input type="button" ng-click="uploadFiles()" value="Upload" />
<!--ADD A PROGRESS BAR ELEMENT.-->
<p><progress id="pro" value="0"></progress></p>
</div>
</body>
Here is my Angularjs Code for multiple file upload(fileupload.js):
var myApp = angular.module('fupApp', []);
myApp.controller('fupController', function ($scope) {
// GET THE FILE INFORMATION.
$scope.getFileDetails = function (e) {
debugger;
$scope.files = [];
$scope.$apply(function () {
debugger;
// STORE THE FILE OBJECT IN AN ARRAY.
for (var i = 0; i < e.files.length; i++) {
$scope.files.push(e.files[i])
}
});
};
// NOW UPLOAD THE FILES.
$scope.uploadFiles = function () {
debugger;
//FILL FormData WITH FILE DETAILS.
var data = new FormData();
for (var i in $scope.files) {
data.append("uploadedFile", $scope.files[i]);
}
// ADD LISTENERS.
var objXhr = new XMLHttpRequest();
objXhr.addEventListener("progress", updateProgress, false);
objXhr.addEventListener("load", transferComplete, false);
// SEND FILE DETAILS TO THE API.
objXhr.open("POST","MailRoute/getDataForUploadFiles");
objXhr.send(data);
}
// UPDATE PROGRESS BAR.
function updateProgress(e) {
debugger;
if (e.lengthComputable) {
document.getElementById('pro').setAttribute('value', e.loaded);
document.getElementById('pro').setAttribute('max', e.total);
}
}
// CONFIRMATION.
function transferComplete(e) {
debugger;
alert("Files uploaded successfully.");
}
});
here is my function in webapi:
public async Task<HttpResponseMessage> getDataForUploadFiles()
{
}
but how to read the file deatils and access the file details from the controller method(getDataForUploadFiles)