Unable to upload file when using JQuery file upload, Spring MVC and Spring Security. -
i implementing simple website image upload. frameworks in use jquery file upload spring mvc spring security
i've implemented form , controller file upload when trying read files, files seems unavailable. i've struggled security _csrf
while i've figured out. when try read files no files can read when reaching controller. here source code https://gist.github.com/adelinghanaem/f67b311cda7aa9efe83c
after lot of debugging , checking spring security/mvc architecture i've came with:
@requestmapping(value = "/upload", method = requestmethod.post) public responseentity<uploadpictureresult> pictureupload(firewalledrequest initialrequest) { defaultmultiparthttpservletrequest request = (defaultmultiparthttpservletrequest) initialrequest.getrequest(); try { multipartfile multipartfile = request.getfile("files[]"); list<multipartfile> multipartfilelist = request.getfiles("files[]"); iterator<string> iterator = request.getfilenames(); while (iterator.hasnext()) { multipartfile file = request.getfile(iterator.next()); service.save(toimage(file)); } } catch (exception e) { return new responseentity<uploadpictureresult>(new uploadpictureresult(), httpstatus.internal_server_error); } return new responseentity<uploadpictureresult>(new uploadpictureresult(), httpstatus.ok); }
notice firewallrequest !!!
Comments
Post a Comment