其余可以与@Produces一起使用MediaType.MULTIPART_FORM_DATA [英] Rest can MediaType.MULTIPART_FORM_DATA be used with @Produces

查看:288
本文介绍了其余可以与@Produces一起使用MediaType.MULTIPART_FORM_DATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个rest服务,它产生这种格式的对象:

I have a rest service which produces the object of this format :

FileDetailsObject {

FileDetailsObject{

byte [ ]数据;
字符串position_of_logo;
字符串用户名;

byte[] data; String position_of_logo; String username;

}

是否有其他方法可以完成此操作?

Is there a way to accomplish this in rest?

如果只是byte [],则可以使用Octet_Stream。但是我需要返回一个带有byte []的对象。

If it was just byte[] , I could use the Octet_Stream. But I need to return an object with a byte[].

我了解到MediaType。 Multipart_Form_Data,但据我了解,它似乎与@Consumes关联,可以在其中将其发送到服务发布请求。

I read about MediaType. Multipart_Form_Data but as far as I understand it seems to be associated with @Consumes where you can send it to a service post request.

任何指针都将有所帮助。

Any pointers would be helpful.

谢谢

推荐答案

您可以在此答案 1 ,或者您可以使用自动转换器(如此答案。关于决定走哪条路,我要说决定因素是谁是客户。某些客户端无法处理多部分响应,但是几乎所有语言都具有某种base64转换方法。

You can use a multipart response like in this answer1 or you can base64 the byte array using an automatic converter like in this answer. On deciding which way to go, I would say the deciding factor would be who are the clients. Some clients can't handle multipart responses, but pretty much all languages have some kind of base64 conversion method.

1。此解决方案特定于泽西岛。您没有指定要使用的JAX-RS实现。

这篇关于其余可以与@Produces一起使用MediaType.MULTIPART_FORM_DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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