Image - SQL Database

#1

save a image to sql using script of ignition

0 Likes

#2

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,

0 Likes

#3

Ok,
thank you

0 Likes

#4

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.

0 Likes

#5

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
0 Likes