Java – @ formdataparam not found in Jersey 2.17

I'm new to web services, so I've started the basic examples This one involves file upload I am using the latest (2.17) version of Jersey bundle for non Maven developers It stated that:

. The problem is that I can't 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 does not exist in Jersey 2.17 package, although docs indicates it 2.17 is the beam incomplete? How to solve this problem?

Solution

The package contains only core modules (and their dependencies) Unfortunately, multipart is not part of the core You also need this dependency (Maven)

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

If you don't use maven, from what I can tell, this artifact has only one other dependency (this is not included in the bundle), and it is mimepull-1.9 three

You can download these two artifacts

> jersey-media-multipart > mimepull-1.9. three

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>