1

I am trying to load an image from the database which is base 64 array into the HTML . it has around 204 characters . I am also trying to load the name and other details .It returns the following JSON

07-18 18:33:52.732: ERROR/HTMLContacts(1098): Json: google json [{"contactId":"1","contactPhoto":"iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAAA3NCSVQFBgUzC42AAAAgAElEQVR4\nnK29f4wc93Un+OnvvBq976iarBKnpSnJbbklj3xDL5kldVJAeqVA9Nne0Ih9J0IRvEIiXHf31AQmUelEgUB0V3d2FhfXu450XTBqlf1Cq+J4QqwisQgMaRGYZpTMUCADkZDS6Reik6n\nKApXTsS54kDn7DdXew/2Sre9eFdR3Jer

Good part of it is truncated . I assume that it has crossed JSON limit hence it truncated the other details . Is there any good way to send the array so that i can display image in HTML ? Thanks in advance .

NOTE : I need to send multiple images maybe 10 at a time .

Preethi
  • 2,112
  • 7
  • 38
  • 54

2 Answers2

2

To use the base-64 data in the SRC of an IMG tag, turn it into a data-url, like so (assuming the image is PNG, change the mimetype as appropriate) :

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAAA3NCSVQFBgUzC42AAAAgAElEQVR4\nnK29f4wc93Un+OnvvBq976iarBKnpSnJbbklj3xDL5kldVJAeqVA9Nne0Ih9J0IRvEIiXHf31AQmUelEgUB0V3d2FhfXu450XTBqlf1Cq+J4QqwisQgMaRGYZpTMUCADkZDS6Reik6n\nKApXTsS54kDn7DdXew/2Sre9eFdR3Jer">
wmorrell
  • 4,988
  • 4
  • 27
  • 37
  • Thanks for the help .It is just a string array "�PNG\r\n\u001a\n\...How do i convert to base 64 – Preethi Jul 19 '11 at 02:10
  • I imagine you would convert it to base-64 just like you did originally. The contactPhoto property of your JSON in the original question is already base-64, so use whatever library you used before to convert the string. – wmorrell Jul 19 '11 at 02:17
1

On browser side, you could refer to this post for base64 encoding. On server side, the ways variant depending on which language you are using on the server side.

Community
  • 1
  • 1
Ghostoy
  • 2,689
  • 19
  • 18