java - File Upload With Jersey Not Working -
i can't jersey file upload work. using jersey 1.9. inputstream null when gets service. i've tried normal form submission , ajax submission using jquery form plugin, same result either way. there no exceptions logged either, making more frustrating.
html form
<form id="doccategoryform" name="doccategoryform" action="someaction" method="post" enctype="multipart/form-data"> document <input type="file" name="fileupload_name" id="fileupload_name" > <button id="submitbutton" type="submit" title="select search">submit</button> </form>
pom
<dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-json</artifactid> <version>1.9</version> <scope>provided</scope> </dependency> <dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-multipart</artifactid> <version>1.9</version> <scope>provided</scope> </dependency>
the dependency hierarchy in eclipse shows mimepull.jar 1.6 getting pulled in.
the rest service
@resourcefilters({requestloggingresourcefilter.class}) @post @path(path_upload) @consumes(mediatype.multipart_form_data) @produces(mediatype.application_json) public myresponseobject uploaddocument(@formdataparam("fileupload_name") inputstream file) { // code }
if add @formdataparam("fileupload_name") formdatacontentdisposition filedetail, fine, inputstream still null.
here request after trying upload simple text file. looks ok me.
* server in-bound request > post http://localhost:7001/webmodule/app/contmang/page/doccategory /uploaddocument > host: localhost:7001 > connection: keep-alive > content-length: 209 > accept: */* > origin: http://localhost:7001 > x-requested-with: xmlhttprequest > user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36(khtml, gecko) chrome/29.0.1547.57 safari/537.36 > content-type: multipart/form-data; boundary=----webkitformboundaryl0uv1kbfovtophto > referer: http://localhost:7001/webmodule/app/contmang/page/doccategory > accept-encoding: gzip,deflate,sdch > accept-language: en-us,en;q=0.8 > cookie: jsessionid_hears=ywhqspfbznh1jfp6hmn4xmfyxxtpybnvttxstykyqxzqyt207wym!-153888503 > entity:------webkitformboundaryl0uv1kbfovtophto content-disposition: form-data; name="fileupload_name"; filename="test.txt" content-type: text/plain hello, world!! ------webkitformboundaryl0uv1kbfovtophto--
thought should bring closure one. problem ended being dumb. somehow wrong inputstream class had been imported. once changed java.io.inputstream worked expected.
Comments
Post a Comment