尝试从角度js上传文件时出现404错误

时间:2017-11-17 10:51:35

标签: javascript angularjs

我正在使用apache tomact服务器。我想从我的angular js HTML应用程序上传文件。  我怎么解决这个问题? 代码是:

 <!DOCTYPE html>
    <html>
    <head>
      <title>AngularJS File Upoad Example with $http and FormData</title>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
    </head>

    <body ng-app="fupApp">
        <div ng-controller="fupController">

            <input type="file" id="file1" name="file" multiple
                ng-files="getTheFiles($files)" />

            <input type="button" ng-click="uploadFiles()" value="Upload" />
        </div>
    </body>

    <script>
        angular.module('fupApp', [])
            .directive('ngFiles', ['$parse', function ($parse) {

                function fn_link(scope, element, attrs) {
                    var onChange = $parse(attrs.ngFiles);
                    element.on('change', function (event) {
                        onChange(scope, { $files: event.target.files });
                    });
                };

                return {
                    link: fn_link
                }
            } ])
            .controller('fupController', function ($scope, $http) {

                var formdata = new FormData();
                $scope.getTheFiles = function ($files) {
                    angular.forEach($files, function (value, key) {
                        formdata.append(key, value);
                    });
                };

                // NOW UPLOAD THE FILES.
                $scope.uploadFiles = function () {

                    var request = {
                        method: 'POST',
                        url: '/fileUploadFolder',
                        data: formdata,
                        headers: {
                            'Content-Type': undefined
                        }
                    };

                    // SEND THE FILES.
                    $http(request)
                        .success(function (d) {
                            alert(d);
                        })
                        .error(function () {
                        });
                }
            });
    </script>
    </html>

这里的文件夹:fileUploadFolder在webapps文件夹中。但我仍然得到错误404文件夹不存在。有人可以帮忙吗

0 个答案:

没有答案