Inserting Image in database using Upload component in perspective

Hi, I am trying to upload an image which is in my local computer to ignition database how can i do that. I have a upload component in my view and I have configured events onFileReceived scripting. The script is

Blockquote# This script is triggered when a file is uploaded
def onFileReceived(self, event, file):
# Get the bytes of the file
image_data = event.file.getBytes()

# Get a database connection
db = system.db.getConnection("MySQLlite")

# Create a SQL query to insert the image data into the database
query = "INSERT INTO image_store (image_name, image_data) VALUES (?, ?)"

# Execute the query
system.db.runPrepUpdate(query, [event.file.name, image_data], db)

# Close the database connection
db.close()

Anyone kindly help me

1 Like

Please use the forum's "preformatted text" button for your script, not blockquote, so we can see everything (including indentation) properly.

Please also share any logged errors (also preformatted) that happen in the gateway logs when you attempt an upload.

2 Likes

Ignition has no such system function.

Don't trust ChatGPT or any other LLM for Ignition specific scripting advice. It will happily and confidently give you completely false information.

8 Likes

Ok @PGriffith I will try to maximum get idea from Ignition Forum answers or my Senior's advice

ok @pturmel I will use preformatted text hereafter