Can't find @FormDataParam in Jersey 2.17

 ̄綄美尐妖づ 提交于 2019-12-30 03:43:14

问题


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

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?


回答1:


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

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


来源:https://stackoverflow.com/questions/29226853/cant-find-formdataparam-in-jersey-2-17

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!