# Converting blob to image

**URL:** <https://forum.inductiveautomation.com/t/converting-blob-to-image/57853>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 31, 2022, 5:37am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853 "2022-03-31T05:37:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando\_Alonso\_Aram](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@Fernando\_Alonso\_Aram](https://forum.inductiveautomation.com/u/Fernando_Alonso_Aram)\
**Post date:** [March 31, 2022, 5:37am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/1 "2022-03-31T05:37:10Z")

</div>

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

 ![1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d0d8ad7fde5a9052830a282e50aa607dd0921866.png)  
 ![1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b19a4eebbb2914b933a967abe309698cf4886284.jpeg)  
Can somebody tell me how to fix this problem?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 31, 2022, 6:15am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/2 "2022-03-31T06:15:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 31, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/3 "2022-03-31T14:28:35Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7a73f30c3720ee03bdf45e3e2a08bae9c3aeee2c.png)

Make your named query a scalar query.

---

<div class="post-metadata">

**Author:** ![Fernando\_Alonso\_Aram](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@Fernando\_Alonso\_Aram](https://forum.inductiveautomation.com/u/Fernando_Alonso_Aram)\
**Post date:** [March 31, 2022, 4:05pm UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/4 "2022-03-31T16:05:20Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/c/cc1c529bafb43d74fdde5ca23a36a83265eb08e6.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 31, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/5 "2022-03-31T16:07:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fernando\_Alonso\_Aram](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@Fernando\_Alonso\_Aram](https://forum.inductiveautomation.com/u/Fernando_Alonso_Aram)\
**Post date:** [April 11, 2022, 3:35pm UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/6 "2022-04-11T15:35:33Z")

</div>

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 ,

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/6/b6fbe124b4467edd855a0d21bbfd31e6c6131538.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 11, 2022, 4:06pm UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/7 "2022-04-11T16:06:37Z")

</div>

Meanwhile, you might want to look at this:

> [@Automation Professionals' Blob Server Module](https://forum.inductiveautomation.com/t/automation-professionals-blob-server-module/57970):
>
> Automation Professionals is pleased to announce an alpha release of its new Blob Server Module. Available only for Ignition v8.1, here. The Blob Server Module provides a simple way to deliver images, PDF files, or other binary content from a database to your Perspective clients or other web applications. Without needing the WebDev module. All you need is a Named Query that has appropriate security settings and returns a single row with two columns: Content, and ContentType. Modest documentati…

(:

---

<div class="post-metadata">

**Author:** ![deepti\_k](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@deepti\_k](https://forum.inductiveautomation.com/u/deepti_k)\
**Post date:** [May 17, 2022, 5:39am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/8 "2022-05-17T05:39:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maria\_P](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Maria\_P](https://forum.inductiveautomation.com/u/Maria_P)\
**Post date:** [March 20, 2024, 9:59am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/9 "2024-03-20T09:59:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 20, 2024, 10:21am UTC](https://forum.inductiveautomation.com/t/converting-blob-to-image/57853/10 "2024-03-20T10:21:16Z")

</div>

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.
