Rest can MediaType.MULTIPART_FORM_DATA be used with @Produces

风格不统一 提交于 2019-12-11 17:41:29

问题


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

FileDetailsObject{

byte[] data; String position_of_logo; String username;

}

Is there a way to accomplish this in rest?

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

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.

Thanks


回答1:


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. This solution is Jersey specific. You didn't specify which JAX-RS implementation you are using.



来源:https://stackoverflow.com/questions/53156815/rest-can-mediatype-multipart-form-data-be-used-with-produces

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