1

One way of doing is to convert the binary data to Base64 and send it along with meta data as MediaType.APPLICATION_JSON.

The problem with this is client has to convert the binary data into Base64 before sending.

I also tried sending using MediaType.APPLICATION_OCTET_STREAM format through REST. This works fine for binary data only.

One option is to send meta data in headers while using MediaType.APPLICATION_OCTET_STREAM.

Is there any better way?

Thanks

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
abhig
  • 840
  • 2
  • 12
  • 22

1 Answers1

1

Use multipart/form-data. This is what it's meant for. Not sure which Jersey version you are using, but here is the link for the Jersey 2.x documentation for Multipart support. Here's for 1.x (not really much information). You will need to do some searching for using multipart with Javascript clients (there is a bunch of information out there)

  • Here is a good example of using Jersey 2.x with both the server side and the client API.
  • Here is an example with Jersey 1.x. You can see the API it not much different.
Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • Thanks @peeskillet. One question : If I want to pass name of parts in multipart/mixed , How can I do it ? Similar to something like http://pastebin.com/bLdsXNhv but using multipart/mixed – abhig May 06 '15 at 23:47
  • Not sure. It seems to be form-data specific. I don't see anything in the API nor in the [RFC](http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html) – Paul Samsotha May 07 '15 at 00:17
  • I will stick to form-data. Any suggestion for getting Binary stream of data along with Metadata – abhig May 07 '15 at 18:15
  • I thought that's what the links I provided do... What exactly is the problem you are facing in doing this? – Paul Samsotha May 07 '15 at 18:17
  • Uploads worked fine. Now, I want to download the file which was upload using upload operation along with its metadata. Any suggestions ? – abhig May 15 '15 at 21:59