Skip to content

Image Grid ​

The Image Grid widget shows the images of capture sessions. Each session has a header with its name, start date, image count and the buttons Upload and Delete, followed by its latest images (up to 12), each with a status label and its source name. The flow feeds the widget an image queue and handles the upload and delete requests the widget sends. The node keeps the widget state across deploys and restarts and rebuilds the sessions from the capture folders on disk.

Palette: category Renders, label image grid. 1 input, 1 output.

Image Grid

Configuration ​

PropertyDescriptionDefault
NameNode name shown in the editor.""
GroupDashboard group that holds the widget. Required.—
LocaleOptional Locale Config for the session dates. Without one, dates are shown as DD/MM/YYYY HH:mm:ss (24-hour clock) in the viewer's time zone.none
SizeWidth and height of the widget (0 = automatic). The grid is 95% of the viewport high and scrolls inside, with a Back to top button.0 x 0
Show bigger last imageOnly for the layout without sessions (see Layout): the first image of the queue is shown large in the left third.off
Images pathTraining (training) or Log (log): the folder under /opt/storage/images whose imageSaveDir subfolders are the capture sessions.training
Flow context keyFlow context variable that holds the flow's image queue. On start, the node fills it with the restored queue when it is empty, and it updates it when a session is deleted or an upload ends. The node also writes the list of session names to <key>Groups. Empty uses trainingQueue; none disables both.trainingQueue
Thumbnail URL prefixURL path under which the browser loads the files of /opt/storage/images. The node uses it to build the image URLs of the sessions it reads from disk./nodered/local/fit/400/images
Image sourcesNumber of Source name fields (minimum 1).1
Source name 1…NNames of the image sources (for example, the cameras). The upload dialog shows one card per name. Names are saved trimmed and in lowercase; when there is more than one field, empty names are dropped.empty

Layout ​

Sessions. The session of an image is the folder that contains its file in imageData (.../imageSaveDir/batch-0412/1732270000000_camera1.jpg belongs to batch-0412). Sessions are listed newest first. Each header shows:

  • the name and the start date: the earliest millisecond timestamp that starts an image name (1732270000000_...), otherwise the time the session was created (the folder's modification time for sessions read from disk);
  • the number of images: the image files in the session folder when the node can read it, otherwise the session's images in the queue;
  • Upload and Delete. While an upload runs, Upload becomes Stop, the progress done / total is shown, and the other sessions' Upload buttons are disabled (one upload at a time). When an upload leaves no image files in the folder, the buttons are replaced by an Uploaded label and a close button that removes the session from the widget.

Below the header, up to 12 images of the session, 2 to 6 per row depending on the screen width, or No images yet. Under each image, its sourceName (else source, else Unknown source).

The status label shows status in capitals: blue for in process and saved, green for done, red for error, grey for any other value (case does not matter). Images without a status have no label.

Session names come from /-separated paths, so give imageData as a URL path: Base64 image data contains / characters and would be split into meaningless sessions.

Without sessions. When no session exists (no image path has a folder and none was created), all images are shown in one grid, and images without a status show a blue UNKNOWN label. With Show bigger last image, the first image is shown large on the left.

Upload dialog. Upload opens Upload — <session> with the number of images and one card per source name, each with a Suffix field and a Dataset list (from datasets). Both are prefilled from the config entry whose sourceName matches. UPLOAD is enabled when at least one source has a dataset; only those sources are sent.

Delete dialog. Delete asks for confirmation; DELETE sends the request and removes the session from the widget and from the stored state. The node does not delete files; that is up to the flow.

Input ​

The properties of an object msg.payload can be combined in one message.

PropertyTypeEffect
msg.payload.imagesQueuearrayReplaces the image queue (see the image fields below) and adds a session for each new folder. An empty array removes the images from the open dashboards (the session headers stay) but not from the node's stored queue, which comes back the next time the widget loads; use "clean" to empty both.
msg.payload.datasetsarray of { id, name }Datasets offered in the upload dialog (name is shown, id is sent).
msg.optionsarraySame as payload.datasets, but only stored: open dashboards get it the next time the widget loads.
msg.payload.configarray of { sourceName, dataset, suffix, folder }Default dataset, suffix and folder of each source in the upload dialog. sourceName must match a configured name (lowercase).
msg.payload.configTrainingarraySame as payload.config when config is absent; only stored, like msg.options.
msg.payload.action = "newGroup" with msg.payload.captureGroupstringCreates an empty session dated now. msg.payload.createGroup (string) does the same.
msg.payload.uploadProgress{ groupName, done, total }Shows done / total on that session and puts it in the uploading state.
msg.payload.action = "uploadComplete" or "uploadStopped" with msg.payload.groupNamestringEnds the uploading state. On uploadComplete, the session is marked Uploaded when its folder has no image files left (or, if the folder cannot be read, when msg.payload.failed is 0). Then the node rebuilds the session from its folder: images whose file is gone are dropped and the newest files fill it up to 12.
msg.payload = "clean"stringEmpties images, sessions and upload state in the node and in the open dashboards; datasets and config are kept. Files are not touched, so sessions whose folders still exist come back the next time the node starts.
msg.queue = true with an array in msg.payloadbooleanReplaces the stored queue like imagesQueue, but open dashboards show it only the next time the widget loads.

Image fields read from each queue entry:

FieldUse
nameFile name. A leading millisecond timestamp (1732270000000_camera1.jpg) gives the session date and, when the node rebuilds a session from disk, the order (newest first). Otherwise images are shown in queue order.
imageDataURL path of the image; its parent folder names the session. Data URLs and raw Base64 (JPEG, PNG, WebP) are also displayed.
sourceNameLabel under the image (source when absent).
statusStatus label: in process, saved, done or error.

Output ​

The widget sends one message on its output for each user action:

Whenmsg.payload
The upload dialog opens{ action: "refreshDatasets" }
UPLOAD is clicked{ action: "uploadImages", groupName, configTraining: [{ sourceName, dataset, suffix, folder }] }
Stop is clicked{ action: "stopUpload", groupName }
DELETE is confirmed{ action: "deleteGroup", groupName }

In uploadImages, configTraining holds only the sources with a dataset, suffix is null when empty, and folder is the session folder: the folder of the matching config entry cut after /imageSaveDir (or whole when it has no /imageSaveDir), else /opt/storage/images/<Images path>/imageSaveDir, followed by /<groupName>.

The flow is expected to answer refreshDatasets with payload.datasets, run the upload for uploadImages (reporting uploadProgress and ending with uploadComplete, including failed, or uploadStopped), stop it on stopUpload, and delete the session files on deleteGroup. Closing an Uploaded session sends nothing.

Persistence ​

The node stores the queue, sessions, datasets and config in the Dashboard datastore, which every dashboard receives when the widget loads, and in <userDir>/image-grid-store/<node id>.json, written one second after the last change and when the node closes. Upload progress is not kept across restarts.

Each time the node starts (deploy or restart) it:

  1. Reads that file and clears the in process status left by an interrupted upload.
  2. When /opt/storage/images exists, drops the images whose file is gone (the part of imageData after /images/, under /opt/storage/images).
  3. Reads /opt/storage/images/<Images path>/imageSaveDir/: each subfolder is a session, and its 12 newest image files (.png, .jpg, .jpeg, .bmp, .webp, .tiff, .tif, .gif, .avif; names starting with thumbnails are ignored) are added when missing. Their imageData is <Thumbnail URL prefix>/<Images path>/imageShowDir/<session>/<name>.webp when that WebP copy exists, else the same path under imageSaveDir with the original file; their sourceName is the last _-separated part of the file name.

Status and errors ​

  • No group configured: node error when no group is set; the widget is not created.
  • ui-image-grid: could not persist state: <message>: warning when the state file cannot be written.
  • ui-image-grid: could not read persisted state: <message>: warning when the state file exists but cannot be read.

Usage example ​

A function node adds each new capture to the shared queue and sends it to the widget (with the default Images path, Flow context key and Thumbnail URL prefix):

js
// msg.session = "batch-0412", msg.filename = "1732270000000_camera1.jpg"
const queue = flow.get('trainingQueue') || [];
queue.unshift({
    name: msg.filename,
    sourceName: 'camera1',
    status: 'saved',
    imageData: `/nodered/local/fit/400/images/training/imageSaveDir/${msg.session}/${msg.filename}`
});
flow.set('trainingQueue', queue);
return { payload: { imagesQueue: queue } };

A second function node, wired to the widget's output, answers the dataset request:

js
if (msg.payload.action === 'refreshDatasets') {
    return { payload: { datasets: [{ id: 'ds-01', name: 'Front caps' }] } };
}
return null;