Image manager - storing images dynamically

I know image management has long been discussed here, but I can not find any solution that works well..

  1. I am uploading an image in perspective. I want to be able to display that image again in perspective.

  2. I cannot find any doc's on programmatically storing that image with the Image Manager.

  3. I don't want to use any BLOBS with databases.

  4. 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

Thanks in advance

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.

Thank you. I am trying to not use WebDev

and

seriously limit your ease of doing this.

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.

1 Like

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.

also @pturmel module seems to no longer be available... the link is crossed out

That is typically a memory issue on the gateway side. You might try increasing gateway memory and seeing if that helps.

We do this frequently with PDFs with no issue.

For the module hopefully, @pturmel will chime in with a valid link.

2 Likes

Crashed my designer and gateway....

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?

Th image is 970kb

If you are curious how to work with ImageManagement programmatically you have to use the ImageManager.

You can get the ImageManager context like:

context  = IgnitionGateway.get()
image = context.getImageManager()

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:

ShowingImageUpload

It also directly uploads to the image management tool in Ignition
image

2 Likes

I updated, but now it just shows the binary data in the html..

So you have it uploading?
But pulling it out isn't working?
How are you pulling it out? With @pturmel module?

Correct. I am using MSSQL, so I don't think its going to work

I believe it should work just find with MSSQL. As long as the columns are setup correctly.

Can you show how you setup the database table?

I have used the Blob serve module before with MSSQL many times and it's always worked for me. v19 and v2022.

I mark links like that when they've been replaced by newer versions. Simply scroll further into the topic.

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