Image Sink
Sink is used to save the picture to the specified folder.
Compile and deploy the plugin
# cd $eKuiper_src
# go build -trimpath --buildmode=plugin -o plugins/sinks/Image.so extensions/sinks/image/image.go
# cp plugins/sinks/Image.so $eKuiper_install/plugins/sinksRestart the eKuiper server to activate the plugin.
Attribute
| Attribute name | Optional | Description |
|---|---|---|
| path | False | The name of the folder where the pictures are saved, such as ./tmp. Note: For multiple rules, their paths cannot be repeated, otherwise they will be deleted from each other. |
| format | False | File format, support jpeg and png. |
| maxAge | True | Maximum file storage time (hours). The default value is 72, which means that the picture can be stored for up to 3 days. |
| maxCount | True | The maximum number of stored pictures. The default value is 1000. The earlier pictures will be deleted. The relationship with maxAge is OR. |
Other common sink properties are supported. Please refer to the sink common properties for more information.
Image filenames consist of the input field name, a timestamp and the image extension. Output files must remain inside the configured path: absolute filenames, parent traversal outside the directory and symlinks pointing outside it are rejected. Relative paths within the directory are supported when their parent directories already exist. Symlinks traversed beneath path must have relative targets that stay within the directory; absolute symlink targets are rejected even when they point inside it. The administrator-configured path retains its existing absolute or relative path semantics and may itself be a symlink. Use a dedicated directory for each image sink.
Usage example
The following example demonstrates how to receive pictures and save them to the folder /tmp. When the number of pictures exceeds 1000, the earlier pictures will be deleted. When the pictures are saved for more than 72 hours, the timeout pictures will be deleted.
{
"sql": "SELECT * from demo",
"actions": [
{
"image": {
"path": "/tmp",
"format": "png",
"maxCount":1000,
"maxage":72
}
}
]
}Demo
In the following example, we take the zmq plugin as source and the image plugin as sink, and save the pictures received by zmq in the folder specified by image.
curl http://127.0.0.1:9081/streams -X POST -d '{"sql":"create stream s(image bytea)WITH(DATASOURCE = \"\",FORMAT=\"binary\", TYPE=\"zmq\");"}'
curl http://127.0.0.1:9081/rules -X POST -d '{"id":"r","sql":"SELECT * FROM s","actions":[{"image":{"path":"./tmp","format":"png"}}]}'