0

Is it possible to send binary data in JSON ? I am creating a REST Service in ASP.NET MVC where i want to return PDF file stored in my server to my clients. How will i do this ? my data transfer medium is JSON & XML.

Happy
  • 1,767
  • 6
  • 22
  • 26
  • 1
    [This](http://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64) post might be useful. – Jeshurun May 25 '12 at 19:04

2 Answers2

1

Take a look here: how to send pdf in json, it lists couple of approaches that you can consider.

The easiest way is to convert the binary data into string by using Base64 encoding. In C#, this would mean a call to Convert.FromBase64String. However this has space overhead as Base64 encoding means around +33% more memory.

If you can get away with it, this is the least complicated solution. in case additional size is an issue you can think about zipping it up.

anurag
  • 77
  • 5
0

If you need a JSON or XML wrapper to your file you'll have to text-encode it, Base 64 for example.

fmgp
  • 1,638
  • 17
  • 17