Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01

拟墨画扇 提交于 2019-12-13 04:53:25

问题


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:

  1. if there's a way I can do it with this jaxrs-ri version
  2. if it's mandatory to change jaxrs-ri version to a more recent one
  3. how to use this annotation

Thank you in advance for your answers!


回答1:


  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.

  1. 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.

  1. 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

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