For a file you can use File
, InputStream
, or byte[]
. For plain text, just use a String. You will also need to annotate the parameter with @FormDataParam("<value>")
, with the value being the name of the part.
@POST
@Path("/user/image")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response addUserImage(@FormDataParam("image") InputStream image,
@FormDataParam("image") FormDataContentDisposition imageDetail,
@FormDataParam("user") String user) {
}
You will need to make sure you have the multipart support dependency. Not sure which Jersey version you are using, but here is for both
Jersey 2.x
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey2.version}</version>
</dependency>
Jersey 1.x
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey1.version}</version>
</dependency>
With Jersey 1.x, it should work out the box without any further configuration. For 2.x, you will need to register the MultiPartFeature
. For help with that, please see this post