AngularJS + Jersey POST错误请求

时间:2016-04-19 05:34:57

标签: angularjs jersey

我在球衣上有以下API用于文件上传:

@Path("/image/upload")
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces("application/json")
    public Response Imageupload(
            @QueryParam("filename") String filename,
            @FormDataParam("file") InputStream fileInputString, 
            @Context ContainerRequestContext crc)
            throws ConnectException, SQLException, InvalidCredentialsException, IOException, GeneralException {
}

我使用角度js上传文件:

_myApp.service('fileUpload', ['$rootScope', '$http', function($rootScope, $http) {
    this.uploadFileToUrl = function(file, uploadUrl) {

        var fd = new FormData();

        fd.append('file', file);




        $http.post(uploadUrl, fd, {
                transformRequest: angular.identity,
                headers: {
                    'Content-Type': 'multipart/form-data',
                    'Authorization': 'Bearer ' + $rootScope.token
                },
                 params:{
                         'filename':file.name
                }
            })
            .success(function() {

            })
            .error(function() {

            });
    }
}]);



_myApp.controller('uploadImageController', ['$rootScope', '$scope', '$http', 'fileUpload', function($rootScope, $scope, $http, fileUpload) {

                $rootScope.show = true;

                $scope.upload = function() {
               //$scope.fileObject is the File I am trying to upload
                        console.log($scope.fileObject);
                        var file = $scope.fileObject;



                        var uploadUrl = "http://xx.xx.xx.xx:8080/ImageAPIS/image/upload";

                        fileUpload.uploadFileToUrl(file, uploadUrl);

                }

我收到以下错误:

400错误请求:客户端发送的请求在语法上不正确。
我是否以错误的Angular标准发布请求?我可以看到发送的有效载荷,泽西岛和我发送的Angular请求之间有什么不匹配?

我已经审阅了以下文件上传代码 -
http://www.tutorialspoint.com/angularjs/angularjs_upload_file.htm

0 个答案:

没有答案