I am trying to upload files in Ignition Perspective but when calling event.file.getBytes()
I am getting an array which is causing the insertion into the database to fail as it is expecting varbinary(MAX). I am working with the example provided in the docs.
def runAction(self, event):
from traceback import format_exc
log = system.util.getLogger("Photo Upload")
try:
filename = event.file.name
filedata = event.file.getBytes()
# Output: <type 'array.array'>
log.info(str(type(filedata)))
except Exception:
log.error(format_exc())
# Use a query to insert the file
# query = "INSERT INTO photos (filename, photodata) VALUES(?, CONVERT(varbinary(MAX), ?))"
# args = [filename, filedata]
# db = self.session.custom.dbConnection
# system.db.runPrepUpdate(query, args, db)
Side note: I think storing files in the database is disgusting so if anyone has tips on where I should store the files using system.file.writeFile()