AngularJS + Jersey POST Bad Request -
i have following api in jersey file upload :
@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 { }
and using angular js uploading file :
_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 file trying upload console.log($scope.fileobject); var file = $scope.fileobject; var uploadurl = "http://xx.xx.xx.xx:8080/imageapis/image/upload"; fileupload.uploadfiletourl(file, uploadurl); }
i getting following error :
400 bad request : request sent client syntactically incorrect.
posting request in wrong angular standard? can see payload being sent, mismatch between jersey , angular request sent?
have refereed following file upload code -
http://www.tutorialspoint.com/angularjs/angularjs_upload_file.htm
Comments
Post a Comment