Skip to Content

Get Image (Binary) from DB and Display HTML

Hi all,

I need to get a binary image in a DB ( SQL Server using SQlQuery) and Display it in a HTML. Anybody Know how to do it?


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Aug 15, 2012 at 01:48 PM


    You can use the data: URI scheme to embed a base64 right into the src attribute of an image tag .

    <img id="myImage" src="data:image/png;base64,/9j/4AAQSkZJRgABAQEAYAB…….”>

    In your case,  use a query template to return the varbinary  as varchar 

    Example:  SELECT CAST(image_text as varchar(max)) AS image_text  FROM ImageTable

    base64Decode the binary string  at the client side by using JavaScript and dynamically modify the “src” attribute of  the <img> tag.

    Use the below to dynamically modify the src attribute (Refer to the attachment for the JavaScript function - Convert).

    document.getElementById("myImage").src=="data:image/png;”+Convert(<<applet>>.getFirstValue(' image_text '));



    PS:  I couldn't  get this into work by using a base64decode  function in BLS or by using a custom SQL function so I did the the conversion at the client side.

    Add comment
    10|10000 characters needed characters exceeded