# Image - SQL Database

**URL:** <https://forum.inductiveautomation.com/t/image-sql-database/10619>\
**Category:** General Discussion\
**Created:** [October 13, 2015, 11:33pm UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619 "2015-10-13T23:33:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert.i](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@robert.i](https://forum.inductiveautomation.com/u/robert.i)\
**Post date:** [October 13, 2015, 11:33pm UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619/1 "2015-10-13T23:33:12Z")

</div>

save a image to sql using script of ignition

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 13, 2015, 11:38pm UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619/2 "2015-10-13T23:38:26Z")

</div>

Hi Robert,

Yes you can do that. You just need to get the bytes of an image and then store it in a blob field in a database.

Something like this would work:

[code]  
#This opens a popup for selecting the image to upload.  
#Returns the path to the image to insert into the database.  
path = system.file.openFile()

if path != None:  
bytes = system.file.readFileAsBytes(path)  
system.db.runPrepUpdate(“INSERT INTO images (BlobImageCol) VALUES (?)”, [bytes])  
[/code]Best,

---

<div class="post-metadata">

**Author:** ![robert.i](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@robert.i](https://forum.inductiveautomation.com/u/robert.i)\
**Post date:** [October 15, 2015, 7:55pm UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619/3 "2015-10-15T19:55:01Z")

</div>

Ok,  
thank you

---

<div class="post-metadata">

**Author:** ![cniemuth](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@cniemuth](https://forum.inductiveautomation.com/u/cniemuth)\
**Post date:** [February 26, 2019, 12:15am UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619/4 "2019-02-26T00:15:33Z")

</div>

I realize this is an old thread, but, how would I retrieve that image/file from the database to save it on another PC? Each ‘system.file’ function that I have been trying doesn’t seem to do it correctly. I also have namedQueries set up as if I were retrieving it to the PDFViewer component, but I am not. I think I get the data back correctly and it returns a large string/byte sample but can’t save a proper file to my desktop. It saves but when I open it, the file is corrupted. Let me know any other details I need and I can post them.

---

<div class="post-metadata">

**Author:** ![paulm1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulm1/32/5900_2.png) [@paulm1](https://forum.inductiveautomation.com/u/paulm1)\
**Post date:** [April 2, 2019, 11:44pm UTC](https://forum.inductiveautomation.com/t/image-sql-database/10619/5 "2019-04-02T23:44:48Z")

</div>

I’m not sure if this will help you or not but I have used the Image component to display .png files that are stored on our system.  
Example: The image path under the Property Editor for the image component I use the following Expression.

```
'file:///' + {Root Container.vFoto.text}

```

Root Container.vFoto.text is a text Field Component that has the following Component Scripting/Mouse/Mouse Released

```
path = system.file.openFile(None,'J:\FULLSAIL\Historian')
if path != None:
event.source.text = path

```

This script allows the user to select an image from a defined folder . When the user selects a file the text looks like this -

```
J:\FULLSAIL\Historian\Session Logo.jpg

```

When combined with the original expression -

```
file:///J:\FULLSAIL\Historian\Session Logo.jpg
```
