0

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");
        }
    }
  • What you need to know is how to send binary content to an ASP.NET controller. This question might help: http://stackoverflow.com/questions/27279729/what-is-the-best-way-to-pass-an-excel-file-to-a-web-api-web-service/27281225#27281225 – Joon Dec 05 '16 at 11:26
  • And this one: http://stackoverflow.com/questions/10320232/how-to-accept-a-file-post-asp-net-mvc-4-webapi – Joon Dec 05 '16 at 11:28
  • Thank you . Do I need to modify only the back end? –  Dec 05 '16 at 12:06
  • _"error 405 is to do with configuration of the Web server"_ No, it means that you post something to a URL that does not support a POST request. Moreover if the question is about server configuration, then add the appropriate tags (server, framework etc.). And why did you ask the same question again? If the previous answer didn't work, then don't accept it. – a better oliver Dec 05 '16 at 12:19
  • Possible duplicate of [Angular upload - error 405 Method Not Allowed](http://stackoverflow.com/questions/40959286/angular-upload-error-405-method-not-allowed) – a better oliver Dec 05 '16 at 12:19

0 Answers0