# Image upload component

**URL:** <https://forum.inductiveautomation.com/t/image-upload-component/59655>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 17, 2022, 6:59am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655 "2022-05-17T06:59:31Z")\
**Posts on this page:** 6\
**Page:** 1

<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, 6:59am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/1 "2022-05-17T06:59:31Z")

</div>

I’ve successfully followed the examples on the forum to upload an image into an SQL database then I am trying to retrieve the saved image from database and show it in image component in perspective. I tried different ways but none of them seems working. In db dataType is varbinary(Max).  
I am trying;  
query as:  
SELECT CAST(’’ as xml).value(‘xs:base64Binary(sql:column(“file\_stream”))’, ‘varchar(MAX)’) from  
Files where name =‘Photo.png’

path=“selectphoto”  
v=system.db.runNamedQuery(path)  
return {‘contentType’:‘image/png’,‘bytes’:v}

Thanks in advance.

---

<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:** [May 17, 2022, 8:08am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/2 "2022-05-17T08:08:46Z")

</div>

Please use the `</>` code formatting button when posting code. You can edit your post with the pencil icon button.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 17, 2022, 8:14am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/3 "2022-05-17T08:14:05Z")

</div>

@pturmel made a module for fetching blobs from a database

> [@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:** ![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:** [May 17, 2022, 11:57am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/4 "2022-05-17T11:57:33Z")

</div>

> [@deepti\_k](#):
>
> v=system.db.runNamedQuery(path)  
> return {‘contentType’:‘image/png’,‘bytes’:v}

The above is wrong. `v` is not an array of bytes. It is a dataset. You need to access the row/column containing the blob. If the first row, as typical, your code should look like this:

```auto
ds = system.db.runNamedQuery(path)
v = ds.getValueAt(0, 'myBlobColumnName')
return {'contentType':'image/png','bytes':v}

```

---

<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:** [May 17, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/5 "2022-05-17T15:30:31Z")

</div>

Or switch your named query type to be a ‘scalar’ query.

---

<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 18, 2022, 5:18am UTC](https://forum.inductiveautomation.com/t/image-upload-component/59655/6 "2022-05-18T05:18:55Z")

</div>

thanks it’s working
