在angularjs(IIS服务器)中文件上传的405方法不允许错误

时间:2016-03-22 20:16:33

标签: angularjs angularjs-directive upload

我在angularjs中创建了上传功能,当我尝试将文件保存在文件夹中时,我不断收到错误405 method not allowed。它在我的IIS服务器上本地完成。

控制器文件:

.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文件:

<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

1 个答案:

答案 0 :(得分:0)

您需要确保本地IIS服务器允许POST请求:

How do I Configure IIS to accept POST requests?

服务器可能还需要允许您尝试上传的文件的mime类型:

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