# Save image help needed

**URL:** <https://forum.inductiveautomation.com/t/save-image-help-needed/8120>\
**Category:** Ignition\
**Created:** [March 7, 2014, 7:44pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120 "2014-03-07T19:44:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 7, 2014, 7:44pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/1 "2014-03-07T19:44:51Z")

</div>

I am working with this code:

`photoID = partID + path
if len(photoID):
	fileName = 'parts/' + photoID + '.jpg'
	file = system.file.openFile()
	if file != None:
		system.file.writeFile(fileName, file)`

the last line is not what I want to do here OR maybe my path is just INCORRECT.

Basically I’d like to let the user find an image file on their machine and then I would save it for them into a builtin Ignition folder. I think this is going to get me the best results for storing/displaying image files.

Anyone know how I can set a fixed path and filename and save to the image browser of Ignition?

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [March 8, 2014, 2:43am UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/2 "2014-03-08T02:43:18Z")

</div>

i don’t know what your paths are or if they are correct but you cant open a jpg without specifying it as a binary file. It goes the same way writing a file.

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 10, 2014, 2:46pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/3 "2014-03-10T14:46:07Z")

</div>

I’m trying to save to a path that is in the builtin folder on the Ignition gateway so permission is gauranteed. I have a department which does not allow me to create shared folders so I must either use a database (which seems like more trouble than it’s worth) or save into the builtin Ignition folder.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [March 10, 2014, 3:15pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/4 "2014-03-10T15:15:13Z")

</div>

Just to verify, you are just trying to move an image from a user selected location (ie… Your desktop) to the default Ignition image location?

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 10, 2014, 4:00pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/5 "2014-03-10T16:00:05Z")

</div>

That is correct, and I want to generate the save filename and location automatically as to not prompt the user for this information.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [March 10, 2014, 5:07pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/6 "2014-03-10T17:07:30Z")

</div>

is the gateway on your local machine or on a server on your network?

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 10, 2014, 5:20pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/7 "2014-03-10T17:20:19Z")

</div>

server

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [March 10, 2014, 5:55pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/8 "2014-03-10T17:55:35Z")

</div>

Whether or not you have security rights to save files depends on what “user” the Ignition Gateway (aka Tomcat) is running as. You can get a more meaningful error message (something like “IOError: Access is denied”) if you specify the current directory in the fileName:

```auto
    fileName = './parts/' + photoID + '.jpg'
```

You should be able to get around this by saving in a public folder (please note the modifications on the last line that I made which saves the actual file instead of just the filename):

```auto
photoID = partID + path
if len(photoID):
   fileName = "c:/users/public/parts/" + photoID + ".jpg"
   file = system.file.openFile()
   if file != None:
      system.file.writeFile(fileName, system.file.readFileAsBytes(file))
```

(second thought: No, this code only works for me because I am on my server machine when testing. You’ll still need something like this, but I’ll have to look for some other choices.)

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 10, 2014, 6:38pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/9 "2014-03-10T18:38:55Z")

</div>

thanks for editing that last line, I didn’t know that I needed to readasbytes to save that file.  
It seems like I was hoping there was a folder in the gateway that could hold the file. When you use the builtin library of images inside the designer you will see what I’m talking about.

---

<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:** [March 10, 2014, 7:42pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/10 "2014-03-10T19:42:53Z")

</div>

Ignition’s builtin library of images are stored in Ignition’s internal database.

---

<div class="post-metadata">

**Author:** ![AJBerera](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AJBerera](https://forum.inductiveautomation.com/u/AJBerera)\
**Post date:** [March 10, 2014, 7:51pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/11 "2014-03-10T19:51:26Z")

</div>

I’d like to write an image in there like you can do by dragging an image into this area in the designer.  
If this is really internalizing these images in a database then I would probably be better off using my own table.  
_Full circle_\*

---

<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:** [March 10, 2014, 9:23pm UTC](https://forum.inductiveautomation.com/t/save-image-help-needed/8120/12 "2014-03-10T21:23:25Z")

</div>

Right. The images are in the IMAGES database table in Ignition’s internal database. You can see them by viewing the Raw Settings Viewer in the Ignition Gateway: Console -\> Advanced -\> Raw Settings Viewer. Then run this query: SELECT \* FROM IMAGES

It would be nice if Ignition provided a scripting function that stored images in its internal database. An Ignition module could be written that exposes such a function.
