在 Jersey 2.17 中找不到 @FormDataParam
我对 Web 服务还很陌生,所以我从基本示例开始.这与文件上传有关.我正在为非 Maven 开发人员使用最新 (2.17) 版本的 Jersey 捆绑包.它指出:
I'm quite new to web services so I've started with basic examples. This one relates to file upload. I'm using latest (2.17) version of Jersey bundle for non-maven developers. It states that:
bundle 包含 JAX-RS 2.0 API jar、所有核心 Jersey 模块 jar 以及所有必需的第 3 方依赖项
bundle contains the JAX-RS 2.0 API jar, all the core Jersey module jars as well as all the required 3rd-party dependencies
.问题是我无法编译这部分:
. The problem is that I can not compile this part:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
String uploadedFileLocation = "d://uploaded/" + fileDetail.getFileName();
// save it
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
return Response.status(200).entity(output).build();
}
似乎 @FormDataParam
在 Jersey 2.17 捆绑包中不存在,尽管文档说它存在.2.17 捆绑包不完整吗?我该如何解决这个问题?
It seems that @FormDataParam
doesn't exist in Jersey 2.17 bundle although docs says it does. Is the 2.17 bundle incomplete? How can I resolve this problem?
推荐答案
捆绑包仅包含核心模块(及其依赖项).不幸的是,Multipart 不是核心的一部分.您还需要 此依赖项 (Maven)
The bundle only includes the the core modules (and their dependencies). Unfortunately, Multipart is not part of the core. You'll need this dependency (Maven) also
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.17</version>
</dependency
如果您不使用 Maven,据我所知,这个工件只有一个其他依赖项(尚未包含在包中),它是 mimepull-1.9.3
.
If you're not using Maven, from what I can tell, this artifact only has one other dependency (that is not already included in the bundle), and it's mimepull-1.9.3
.
您可以在下面下载这两个工件
You can download both artifacts below
- jersey-media-multipart
- mimepull-1.9.3
相关文章