问题
I am using jaxrs-ri-2.01 I would like to get in a parameter the binary data that is sent in the body of my HTTP PUT request.
I have found one annotation that should do the trick :
@FormDataParam
but it does not seem to be available for the jaxrs-ri-2.01
I would like to know:
- if there's a way I can do it with this jaxrs-ri version
- if it's mandatory to change jaxrs-ri version to a more recent one
- how to use this annotation
Thank you in advance for your answers!
回答1:
- if there's a way I can do it with this jaxrs-ri version
You need the jersey-media-multipart
. This has the multipart support. If you are using Maven, add
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.0.1</version> <!-- or whatever version
</dependency> you plan to use. -->
If you are not using Maven, you can find the download here. Scroll down and select the Jersey version you are using. Then click the Download (Jar) button to download. You will also need the mimepull
jar that goes with it. To find it, scroll down and click version button that goes with mimepull
.
- if it's mandatory to change jaxrs-ri version to a more recent one
Any 2.x version will have the multipart support in a different artifact, as mentioned above.
- how to use this annotation
First you will need to register the MultiPartFeature
. See here for help. Then just do something like
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(@FormDataParam("file") InputStream file) {
...
}
See Also (for details and examples):
- Jersey documentation for Multipart
- File upload along with other object in Jersey restful web service
来源:https://stackoverflow.com/questions/33956085/upload-binary-data-with-http-put-with-jersey-jaxrs-ri-2-01