-->

Rest can MediaType.MULTIPART_FORM_DATA be used wit

2019-08-27 18:43发布

问题:

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.