Skip to main content

File Storage Overview

The FILE_STORAGE connector writes MQTT messages to local CSV or JSON files. It provides simple persistence for logging, backups, and data export without requiring a database server.
File storage is ideal for simple logging, local backups, and exporting data for offline analysis. Use it when you don’t need a full database but want persistent records.

Basic Syntax


Connection Configuration

FILE_STORAGE_CONFIG Parameters

string
required
Directory for the files. Use a relative path such as "logs": it resolves under the broker’s storage root, so the same connector works on every host. See Where files are written.
string
File name pattern. {0} is replaced with the table name. Default: {0}.csv for CSV and {0}.json for JSON.{0} is the only placeholder. Others, such as {date}, are not supported: the connector fails when it writes. For daily files, publish to a table name that includes the date.
string
File format: CSV or JSON. Default: JSON.
string
CSV delimiter character. Default: comma (,).
boolean
Append to existing files. Default: true.
boolean
Add a timestamp field to each record, unless the record already has one. Default: true.
integer
JSON only: the most records a file keeps. Older records are dropped once the file is full. Default: 10000. Files are not rotated.
string
Timestamp format string. Default: yyyy-MM-dd HH:mm:ss.
Use environment variables for paths in production. Keep deployment-specific values out of your connector definitions:
See Environment Variables & Secrets for setup and usage.

Where files are written

A relative STORAGE_DIR resolves under the broker’s storage root, the storage folder in the broker’s data directory. Files then live with the rest of the broker’s data. In Docker, that is the data volume, so they survive a container recreate. Setting COREFLUX_DATA_PATH (or CONFIG_PATH) moves the storage root with the data directory. The broker always refuses a STORAGE_DIR that points at the data directory itself, the install directory, or the broker’s own bin/, config/, projects/, log/, logs/, stats/, or cluster/ folders. A FILE_PATTERN, or a table name from an event query, that would place a file outside STORAGE_DIR (with .. or an absolute path) is refused too. Set the environment variable COREFLUX_STORAGE_RESTRICT_TO_ROOT=true to refuse every path outside the storage root, including absolute paths and the working-directory fallback. It is off by default so existing connectors with absolute paths keep working. Turn it on where AI assistants deploy connectors.

Deploy checks the folder

When you add a FILE_STORAGE connector, the broker resolves STORAGE_DIR, creates the folder, and writes a test file before it accepts the connector. If that fails, the error names the storage root and a relative path to retry with:
An AI assistant connected to the broker’s MCP Server can call the read-only get_storage_locations tool first. It reports the OS, whether the broker runs in a container, the data directory and storage root (each with a write check and free space), and a recommended relative STORAGE_DIR.

CLEAN Query Format

File storage connectors use the CLEAN format:
The table name is used in the file pattern with {0}.

Writing Data

Log sensor data to daily CSV files:
Creates sensor_data.csv under the storage root’s logs folder.
Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this connector. Every PUBLISH MODEL call automatically inserts a row — no query needed:
See Data Storage Overview for the full STORE IN workflow.

Reading Data

EVENTs also support read queries to retrieve data from stored files. Publish a message to the event’s SOURCE_TOPIC, and the matching rows are published to DESTINATION_TOPIC as one JSON array. File Storage read queries use the CLEAN format with filter, sort, and limit instead of SQL. A query is a store when its object has a top-level data key, and a read otherwise. A filter or projection that names a field called data is still a read. filter, sort, skip, limit, and projection apply to CSV and JSON files alike. CSV cells are compared as numbers when the value in the filter is a number, so {count: {$gte: 7}} works on a CSV file.
To trigger this query, publish the sensor ID to the source topic:
The matching record is published to file/result/latest, where your actions or external clients can consume it. One connector can store and read the same table. The automatic column is timestamp, so sort by it to get the newest rows:
Publish any message to historian/packer01/query to get the 100 newest rows on historian/packer01/result. An assistant on the MCP Server can run the read event directly with run_connector (target: Packer01History.QueryPacker01State).

CLEAN Read Operators

limit is applied before skip: limit: 10, skip: 5 returns rows 6 to 10 of the result.

File Pattern Placeholders

{0} is the only supported placeholder. A pattern with others, such as {date}, fails when the connector writes.

Output Examples

CSV Output

JSON Output (JSON Lines format)


Troubleshooting

  • Use a relative STORAGE_DIR so files go under the storage root. See Where files are written
  • For an absolute path, check that the folder exists and that the broker process can write there
  • Read the deploy error: it names the storage root and a relative path to retry with
  • Check where a relative STORAGE_DIR resolves on this host in Where files are written
  • Look for a deprecation warning in the log: an older relative folder under the working directory is still used
  • Check disk space is available
  • Verify SOURCE_TOPIC matches incoming messages
  • Check QUERY syntax is correct
  • Verify APPEND is set correctly
  • FILE_PATTERN accepts only {0} (the table name). Remove other placeholders such as {date}.
  • For JSON, MAX_RECORDS caps the file and drops the oldest records. Files are not rotated.

Next Steps

Data Storage Connectors Overview

Compare all storage options.

PostgreSQL Connector

Configure PostgreSQL database storage.
Last modified on December 4, 2026