Good afternoon, everyone.
I've been trying to get the signaturepad component to log a byte array to MS sql server, and then to pull that array back out of the server to display in an image component on a report. Searching the forum, I've only found one solution which was to save the image to the gateway, then to log the path to the database and retrieve the image for display that way. I don't particularly like this approach, as we now have the image files to deal with. According to the Ignition manual, I should be able to achieve my approach. However, even with no errors reported by my scripts, the image will not display. Has anyone gotten this to work in the manner I've described? If so, what were the steps?
If you're storing raw binary bytes, then you need to base64 encode those bytes and make them into a data URL to actually display it via a Perspective image component.
To store the data, I'm using signatureBinary = event.signatureFile.getBytes()
and to retrieve it I do a
results = system.db.runPrepQuery(query, [inspectionID], database=databaseName)
if results and len(results) > 0:
signatureBinary = results[0]["Signature"]
then encode with
if signatureBinary:
base64String = base64.b64encode(signatureBinary).decode()
dataUrl = '<img src="data:image/png;base64,{}" width="300" height="100" alt="Signature">'.format(base64String)
and return with
data["Signature"] = dataUrl
Is that correct?
Actually, since you mentioned displaying images in reports, you just need the raw byte array.
So you don't need a data URI at all; just set data["Signature"]
to the inner element of the query (consider system.db.runScalarPrepQuery
), and the add an image component and set its data key to Signature
and it should just work, as long as you're on a fairly recent 8.1 version.
That finally got it, thank you. The image isn't great, but it shows up at least!
edit:image is fine, just had to make it bigger.