1

If, in addition to binary image data, I want to also return a data structure in the same http response message. That data structure would describe the image further so the receiving application could use that information to process the image if it wanted to, what would be the way to do it?

When transmitting just that data structure without the image data, I'd probably just return it as JSON.

  1. Like any other image, with an image/... Content-Type, but adding custom http response headers containing the extra data
  2. Using application/json (or xml or ...) containing the json data structure and a field containing the encoded binary image data
  3. As Metadata in the image binary itself, although that would be specific to the type of image used (png different than gif etc.)

1) would be the easiest for me to implement both server-side and client-side, I just wonder, if that's not abusing http headers, otoh. maybe this would be similar to some of the standard http headers like ETags.

2) and 3) aren't as easy to use both client- and server-side, and 2) would also not be as efficient (CPU, bandwidth) as 1) and 3).

The nice thing about 1) and 3) would be that clients unaware of the metadata (JS client?) could at least display the image.

Any objections to 1) from the HTTP police? Any other option I missed?

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156

2 Answers2

1

If you're making up your own protocol (client and server), you can do pretty much anything you want.

However, I'd recommend not to reinvent the wheel; for instance consider the Link header field using a link relation such as "describedby".

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • +1 Existing specifications already provide a surprising variety of solutions to problems where the instinctrive reaction is to invent something. – Jan Algermissen Oct 12 '11 at 09:53
  • It's really application-specific data, there won't be anything in the standards for that. Otoh, if I could transfer it as 'standardy' as possible, that would be great in terms of the range of clients that can potentially access the data. – Evgeniy Berezovsky Oct 13 '11 at 00:49
1

4) Content-Type = multipart/mixed. But if you're using a browser, see here.

Community
  • 1
  • 1
fumanchu
  • 14,419
  • 6
  • 31
  • 36
  • Thanks for the hint. Actually displaying the image in a plain browser (without using Ajax/XHR) is not the main objective, so if the main client platforms I'm targeting (including XHR) can cope with it, multipart/mixed looks like exactly what I need. Will check it out. – Evgeniy Berezovsky Oct 13 '11 at 00:48