我无法让泽西文件上传工作。使用泽西岛 1.9。InputStream 在到达服务时为空。我已经尝试将其作为普通表单提交和使用 jQuery Form 插件的 AJAX 提交,但无论哪种方式都得到相同的结果。也没有记录异常,这更加令人沮丧。
HTML 表单
<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 to search">Submit</button>
</form>
聚甲醛
<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>
Eclipse 中的 Dependency Hierarchy 显示 mimepull.jar 1.6 也被引入。
REST 服务
@ResourceFilters({RequestLoggingResourceFilter.class})
@POST
@Path(PATH_UPLOAD)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public MyResponseObject uploadDocument(@FormDataParam("fileupload_name") InputStream file) {
// Some code
}
如果我添加@FormDataParam("fileupload_name") FormDataContentDisposition fileDetail,我会得到很好的结果,但 InputStream 仍然为空。
这是尝试上传简单文本文件后的请求。在我看来还可以。
* 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, like 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--