无法使用angular JS和Spring控制器上传文件

时间:2016-05-25 10:19:29

标签: javascript angularjs

我不理解url:'/ api / fileupload /', $ scope.uploadFiles = function(){

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

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

1 个答案:

答案 0 :(得分:0)

这是我前一段时间使用angular:

上传xlm文件的代码
this.uploadFile = function($file) {
        // $http() returns a $promise that we can add handlers with .then()
        return $http({
            method: 'POST',
            url: restUrl + "/rest/data/upload",
            data: $file,
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        })

还要确保您接受服务器上的MediaType.MULTIPART_FORM_DATA