I am trying to upload a video file with angular. I am getting error 405. Reading further in the net I found out that error 405 is to do with configuration of the Web server and security governing access. How can I fix this error.
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) {
$http.post(uploadUrl, file,{
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
})
.success(function () {
console.log(1);
})
.error(function () {
console.log(2);
});
}
}]);
MyApp.controller('AdminController', ['$scope', '$http', '$location', 'fileUpload', function ($scope, $http, $location, fileUpload) {
var baseUrl = $location.protocol() + "://" + location.host + "/";
$scope.uploadFile = function () {
var file = $scope.myFile;
$http.post(baseUrl + "fileUpload", { data: file });
};
}]);
[HttpPost]
public ActionResult uploadFile(dynamic data)
{
try
{
Model mcqModel = new Model();
Console.Write(data);
Response.StatusCode = 200;
return Content("updated");
}
catch (Exception ex)
{
Response.StatusCode = 500;
return Content("Fail");
}
}