0

I have created upload functionality in angularjs and when I am trying to save the file in the folder I keep getting the error 405 method not allowed. It's done locally on my IIS server.

controller file :

.controller('fileuploadCtrl',  ['$scope','$route','$upload', function ($scope,$route,$upload) { 

    $scope.upload = function (files) {
        if (files && files.length) {
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                //var path = 'temp/files/' + $scope.information.id + '-' + file.name;
                var path = 'temp/files';
                $upload.upload({
                    url: path,
                    file: file,
                    fields: {
                        'username': $scope.username
                    },
                    headers: { 'Content-Type': 'multipart/form-data' }
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);

                    $scope.percentComplete = progressPercentage;
                    $scope.items.attachment = evt.config.file.name;

                }).success(function (data, status, headers, config) {

                }).error(function (data, status, headers, config) {

                });
            }
        }
    };

}]);

HTML file :

<input type="file" ng-file-select name="file" ng-file-change="upload($files)"  >
<div class="progress" style=" margin: 0%">
    <div class="progress-bar" role="progressbar" ng-style="{ 'width': percentComplete + '%' }" style="width: 0%;">
        <span ng-if="percentComplete === 100">{{items.attachment}} upload completed successfully</span>
    </div>
    <span ng-if="percentComplete > 0" class="fileupload">{{percentComplete}}%</span>
 </div>

Screenshot given below

Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
  • Do you have a backend to handle the receipt of the file? You have to have something that handles the receipt which more than likely involves some other language, like PHP, Ruby, Perl, C#, etc. – MiltoxBeyond Mar 22 '16 at 20:20
  • Hello miltox, i am using nodeJS to handle the backend. – Anupam Bhaskar Apr 05 '16 at 14:37
  • What port are you using for the nodejs backend? If you are using another port, you have to make sure the upload is sent to the correct server. Currently you are sending the file to temp/files on your frontend server which either doesn't exist or is not equipped to respond to an actual file upload. – MiltoxBeyond Apr 05 '16 at 20:57

1 Answers1

0

You need to ensure your Local IIS Server allows POST requests:

How do I Configure IIS to accept POST requests?

The server might also need to allow the mime-type of the file you are trying to upload:

https://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx

Community
  • 1
  • 1
itsphilz
  • 455
  • 2
  • 9
  • Hello @itsphilz , i am trying to upload pdf files. I have .pdf extension added to the mime types but its still not working. I am not sure what verbs to add in handler mappings. Could you please let me know in detail .thanks – Anupam Bhaskar Apr 05 '16 at 14:36