# Saving and restoring files to and from a database

**URL:** <https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458>\
**Category:** General Discussion\
**Created:** [June 13, 2018, 8:12pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458 "2018-06-13T20:12:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssilk76](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@ssilk76](https://forum.inductiveautomation.com/u/ssilk76)\
**Post date:** [June 13, 2018, 8:12pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458/1 "2018-06-13T20:12:23Z")

</div>

I am pretty ignorant when it comes to the true power of the database side of ignition. One thing I was wondering is if I can store entire files such as images (.jpg) or drawings (.dxf) in the database itself and be able to recall those at will. I currently use a local file path and then just display files based on those paths but I would like to centralize these images so if a client doesn’t have access to network drive the images can still be accessed. I have found a few mentions that this is possible in the forums (readfileasbytes???) but nothing about how to store them or restore them?

And of course the follow up to this would be, are there any examples anywhere?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 13, 2018, 8:24pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458/2 "2018-06-13T20:24:48Z")

</div>

Make sure your db has a column of type BLOB (or its variants). Your image is really just a byte array – you store the bytes in the database and later retrieve them, just like reading the file from disk.

---

<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:** [June 13, 2018, 9:31pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458/3 "2018-06-13T21:31:37Z")

</div>

I all you really want is central storage without having to deal with drive mappings and file services, you can use [system.util.sendRequest()](https://docs.inductiveautomation.com/display/DOC79/system.util.sendRequest) to delegate to a message handler on the gateway and use [system.file.readFileAsBytes()](https://docs.inductiveautomation.com/display/DOC79/system.file.readFileAsBytes) there, sending the response bytes back to the client.

---

<div class="post-metadata">

**Author:** ![ssilk76](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@ssilk76](https://forum.inductiveautomation.com/u/ssilk76)\
**Post date:** [June 14, 2018, 7:04pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458/4 "2018-06-14T19:04:09Z")

</div>

Although I believe understand the theory I do not understand how to carry it out. Would these be standard SQL commands I could use in a script or are we at python/jython level at this point?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 14, 2018, 8:34pm UTC](https://forum.inductiveautomation.com/t/saving-and-restoring-files-to-and-from-a-database/18458/5 "2018-06-14T20:34:02Z")

</div>

The only python scripting would be a call to [system.db.runQuery](https://docs.inductiveautomation.com/display/DOC79/system.db.runUpdateQuery) and its variants. That query will be just standard SQL, and a google search will give you a whole lot of examples of storing and retrieving images.
