cancel
Showing results for 
Search instead for 
Did you mean: 

Get Image (Binary) from DB and Display HTML

former_member193964
Active Participant
0 Kudos

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?

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Marcelo,

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 '));

Thanks,

Johnson

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.

former_member214677
Active Participant
0 Kudos

Great! It works! thanks!

Answers (0)