java - 406 fail without any prompt in process of uploading file -
i'd upload file , in same time send property - reviewid. thats why create , java controller:
@preauthorize("hasanyauthority('client', 'worker')") @requestmapping(value = "", method = requestmethod.post, headers="accept=*/*", produces = {"multipart/form-data", "application/json"}, consumes = {"multipart/form-data", "application/json"}) public void uploadfile(@requestpart("file") list<multipartmodel> files, httpservletrequest httprequest) { principal name = httprequest.getuserprincipal(); if (name.getname() == null) { throw new runtimeexception("brak sesji"); } user userbylogin = userdao.finduserbylogin(name.getname()); file f = null; (multipartmodel file : files) { if (!file.getmultipartfile().isempty()) { review byreviewid = reviewservice.findbyreviewid(file.getreviewid()); try { f = new file(file.getmultipartfile().getoriginalfilename(), file.getmultipartfile().getbytes(), file.getmultipartfile().getname(), file.getmultipartfile().getcontenttype(), new date(), userbylogin, byreviewid); } catch (ioexception e) { e.printstacktrace(); } } if (f != null) { fileservice.uploadfile(f); } } }
in multipartmode' have the
multipart` object , integer reviewid.
while try send post
request have bug http 406
without prompt. headers looks like:
i created junit test if service responsible uploading file works - , works. when creating request browser doesn't work.
my .js file reposnible uploading:
angular.module('sbadminapp').directive('addfile', function () { return { templateurl: 'static/app/scripts/directives/addfile/addfile.html', restrict: 'e', replace: true, controller: function ($scope, $log, uiuploader) { console.log('scope', $scope.reviewid); var multipart = []; $scope.btn_remove = function (file) { $log.info('deleting=' + file); uiuploader.removefile(file); }; $scope.btn_clean = function () { uiuploader.removeall(); }; $scope.btn_upload = function () { $log.info('uploading...'); uiuploader.startupload({ url: '/api/file', concurrency: 2, onprogress: function (file) { $log.info(file.name + '=' + file.humansize); $scope.$apply(); }, oncompleted: function (file, response) { $log.info(file + 'response' + response); } }); }; $scope.files = []; var element = document.getelementbyid('file1'); element.addeventlistener('change', function (e) { var file = e.target.files; console.log('--', e, '===', file); var multipartfile = {multipartfile: file, reviewid: $scope.reviewid}; multipart.push(multipartfile); console.log('mulitpart', multipart); uiuploader.addfiles(multipart); $scope.files = uiuploader.getfiles(); $scope.$apply(); }); $scope.btn_clean(); } } });
Comments
Post a Comment