java 在 Jersey 2.17 中找不到 @FormDataParam

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29226853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:53:28  来源:igfitidea点击:

Can't find @FormDataParam in Jersey 2.17

javarestjerseymultipartform-datajersey-2.0

提问by Rasa

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:

我对 Web 服务很陌生,所以我从基本示例开始。这一项与文件上传有关。我正在为非 Maven 开发人员使用最新 (2.17) 版本的 Jersey 包。它指出:

bundle contains the JAX-RS 2.0 API jar, all the core Jersey module jars as well as all the required 3rd-party dependencies

bundle 包含 JAX-RS 2.0 API jar、所有核心 Jersey 模块 jar 以及所有必需的第 3 方依赖项

. 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();
}

It seems that @FormDataParamdoesn't exist in Jersey 2.17 bundle although docs says it does. Is the 2.17 bundle incomplete? How can I resolve this problem?

@FormDataParam尽管文档说它确实存在,但 Jersey 2.17 包中似乎不存在。2.17 捆绑包不完整吗?我该如何解决这个问题?

回答by Paul Samsotha

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

该包仅包含核心模块(及其依赖项)。不幸的是,Multipart 不是核心的一部分。您还需要此依赖项(Maven)

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.17</version>
</dependency

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.

如果您没有使用 Maven,据我所知,这个工件只有一个其他依赖项(尚未包含在捆绑包中),并且它是mimepull-1.9.3.

You can download both artifacts below

您可以下载下面的两个工件