使用jersey jaxrs-ri-2.01通过HTTP PUT上传二进制数据 [英] Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01

查看:150
本文介绍了使用jersey jaxrs-ri-2.01通过HTTP PUT上传二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jaxrs-ri-2.01 我想在参数中获取HTTP PUT请求正文中发送的二进制数据.

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

但是它似乎不适用于jaxrs-ri-2.01

but it does not seem to be available for the jaxrs-ri-2.01

我想知道:

  1. 如果有办法可以使用此jaxrs-ri版本
  2. 如果必须将jaxrs-ri版本更改为最新版本
  3. 如何使用此注释

预先感谢您的回答!

推荐答案

  1. 如果有办法可以使用此jaxrs-ri版本

您需要jersey-media-multipart.这具有多方面的支持.如果您使用的是Maven,请添加

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

如果您不使用Maven,则可以找到这里.向下滚动并选择您正在使用的Jersey版本.然后单击下载(Jar)按钮进行下载.您还将需要附带的mimepull jar.要找到它,请向下滚动并单击mimepull附带的版本按钮.

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. 如果必须将jaxrs-ri版本更改为最新版本

如上所述,任何2.x版本都将在不同的工件中提供多部分支持.

Any 2.x version will have the multipart support in a different artifact, as mentioned above.

  1. 如何使用此注释

首先,您需要注册MultiPartFeature.请参阅此处以获取帮助.然后做类似的事情

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

这篇关于使用jersey jaxrs-ri-2.01通过HTTP PUT上传二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆