在Jersey 2.17中找不到@FormDataParam [英] Can't find @FormDataParam in Jersey 2.17
问题描述
我对网络服务很陌生,所以我从基本的例子开始。这个涉及文件上传。我正在为非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模块罐以及所有必需的第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
这篇关于在Jersey 2.17中找不到@FormDataParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!