Save image help needed

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?

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.

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.

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?

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

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

server

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:

    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):

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.)

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.

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

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*

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.