Converting blob to image

Hi.
Im using script to store filedata as varbinary(max) in mssqlserver.
but the problems comes when im trying to display the image in perspective.
im copying some of the scrips i see in some related topics

I’m using this query to select and convert the blob to base64:

SELECT CAST(’’ as xml).value(‘xs:base64Binary(sql:column(“filedata”))’, ‘varbinary(MAX)’)
FROM files
WHERE filename = ‘04E.JPG’
then this script transform to display the image:

b64Image = “data:image/jpeg;base64,%s”%value
return b64Image

But it doesn’t display anithing, i think some parameter is missing



Can somebody tell me how to fix this problem?

Tip: use the </> code formatting button to preserve code indentation and apply syntax highlighting. It’s essential for Python and makes any code much easier to read. There’s an edit button (pencil icon) below your post so you can fix it.

Make your named query a scalar query.

1 Like

i made it scalar query, now it brings this array, but no image is shown.

Your query is returning a raw byte array, not a base64 string. You need to adjust your query.

Thank you so much, I managed to convert the array in string using the embed functions of ignition. as i struggled so much with the scripting, but it does the job.
As i only know ladder prog. Im discovering this phyton programing ,

Meanwhile, you might want to look at this:

(:

i used same code still i am not able to get it.

I'm trying to show an image stored in dabatase in vision, with an image object.
should this solution work also for vision module?

I'm showing images in a power table column but its not best approach for that.

Maria, this thread is for Perspective. I suggest that you start a new thread for your Vision query. Reference this one if it's relevant.