6

I have a web application that allows a client to request several image thumbnails at once. The response is currently sent as a JSON-encoded list of objects where each object includes the (encoded) image data. (I'm using JSON.NET; it looks like it's encoding the image data as base64 strings).

If I change my application such that the image data is sent separately from the JSON object, as "binary" (application/octet-stream) content, will this be more efficient?

Or put more simply, is application/octet stream a more compact encoding than base64?

Also, how does this differ from image/jpeg?

Gary McGill
  • 26,400
  • 25
  • 118
  • 202

1 Answers1

9

OK, so application/octet-stream is essentially binary, which is - of course - more efficient than base64. Something like 30% more efficient in terms of space, and removes the need to encode/decode.

Gary McGill
  • 26,400
  • 25
  • 118
  • 202
  • I wonder what the benefit of using base64 then? As far as I see it's only to be backward-compatible/workable with old systems (e.g SMTP) – HieuHT Jul 04 '17 at 19:49
  • 1
    @HieuHT: Yes, it means that the message contains only regular ASCII characters, and so it can safely be passed around without worrying about character-set translation and without it being accidentally interpreted as something other than text. See https://en.wikipedia.org/wiki/Base64 – Gary McGill Jul 06 '17 at 09:35
  • For people from future and @HieuHT , here's the answer for why base64 is used for binary data in json: https://stackoverflow.com/a/67156941/8283737 – Arun Gowda Feb 22 '23 at 15:20