I know image management has long been discussed here, but I can not find any solution that works well..
I am uploading an image in perspective. I want to be able to display that image again in perspective.
I cannot find any doc's on programmatically storing that image with the Image Manager.
I don't want to use any BLOBS with databases.
I have managed to save the image to a drive on the Gateway, but servicing them to a perspective session is proving to be troublesome, unless someone know a magic folder that can be viewed in http://example:8088/image.png
I don't know if you can import image by script in the image manager.
But one solution is to save the image in a folder somewhere.
And then with the WebDev module (or a custom web server like Flask with Python, if you don't have the WebDev module) give access to your image. These image will be available with an URL like your 4th point.
A blob in the database coupled with a WebDev resource, or @pturmel Blob module is the most efficient Ignition centric way to get this done (that I know). Anything else would be either unsupported, or fragile and prone to breaking in future version.
The Ignition image management stores the data in a database as well... just SQLite rather than a robust database.
I understand all this, but using the getBytes() to store in an MSSQL column and then pulling it back out seems to AWAYS crash either my designer, or the whole gateway. If someone could point me to a resource of examples that work in this regard, I could revisit that.
Can you grab something from the logger showing the error? You may need to get into the wrapper.log to get the error as it was crashing.
How big is the file you are uploading?
Can you post your code?
This then give you access to use the functions getImage, getImages, insertImage, deleteImage like from the javadoc I linked. Keep in mind I believe you have to be gateway scoped but since you tagged perspective you should be fine
from javax.imageio import ImageIO
from java.io import ByteArrayInputStream
from com.inductiveautomation.ignition.gateway.images import ImageManager, ImageFormat
from com.inductiveautomation.ignition.gateway import IgnitionGateway
# Obtain the GatewayContext
gatewayContext = IgnitionGateway.get()
# Get the ImageManager
imageManager = gatewayContext.getImageManager()
imageBytes = event.file.getBytes()
# Convert the image bytes to a ByteArrayInputStream
byte_stream = ByteArrayInputStream(imageBytes)
# Use ImageIO to read the image from the byte stream
buffered_image = ImageIO.read(byte_stream)
# Get the width and height of the image
width = buffered_image.getWidth()
height = buffered_image.getHeight()
# Other Variables
Name = event.file.name
Description = event.file.name
Imagetype = ImageFormat.PNG
directory = ''
#ImageType = event.file.name.split('.')[-1].upper()
inputfile = imageBytes
size = len(inputfile)
#Upload to image manager
imageManager.insertImage(Name,Description,Imagetype,directory,inputfile,width,height,size)
I wrote this code it goes directly into the file upload component this was a fast mock up so if you want security and verification I would add a button that runs this script.
Here is the example in use:
It also directly uploads to the image management tool in Ignition
CREATE TABLE asset_images (
id INT IDENTITY PRIMARY KEY,
assetId INT NOT NULL,
name VARCHAR(255) NOT NULL,
Content VARBINARY(MAX) NOT NULL,
ContentType VARCHAR(25) NOT NULL,
uploadDate DATETIME DEFAULT GETDATE(),
fileSize INT
FOREIGN KEY (assetId) REFERENCES assets(id) ON DELETE CASCADE
);
SELECT Content, ContentType
FROM asset_images
WHERE id = :id