Orkun
Orkun

Reputation: 512

Send JSON with Binary File in JAX-RS

I want to ask that how to send json with binary file attachment in jax-rs. I mean a java class producing the both. Can someone answer with an example ? Thanks for answering.

Upvotes: 1

Views: 781

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209004

I see a couple options, both with some disadvantages.

You could...

Use multipart as the response type. You can see an example in this post. Also see Jersey Multipart Documentation. Note that not all clients support consuming multipart; some only support sending multipart data.

You could...

Base64 encode the file to a string and just add it as part of the JSON. One limitation of this is the entity size will be inflated. Base64 encoding will increase the size of the file.

Upvotes: 1

Related Questions