Skip to main content

File Storage Overview

The FILE_STORAGE route 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

STORAGE_DIR
string
required
Directory path for storing files.
FILE_PATTERN
string
File name pattern. Use {0} for table name, {date} for current date. Default: {0}.csv
FORMAT
string
File format: CSV or JSON. Default: CSV.
CSV_DELIMITER
string
CSV delimiter character. Default: comma (,).
APPEND
boolean
Append to existing files. Default: false (overwrite).
INCLUDE_TIMESTAMP
boolean
Auto-add timestamp field. Default: false.
MAX_RECORDS
integer
Maximum records per file before rotation. Default: 10000.
DATE_FORMAT
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 route definitions:
See Environment Variables & Secrets for setup and usage.

CLEAN Query Format

File storage routes 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 files like: sensor_data_2025-01-15.csv
Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this route. 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 query result is published to DESTINATION_TOPIC. File Storage read queries use the CLEAN format with filter, sort, and limit instead of SQL:
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.

CLEAN Read Operators


File Pattern Placeholders


Output Examples

CSV Output

JSON Output (JSON Lines format)


Troubleshooting

  • Verify STORAGE_DIR exists
  • Check write permissions on directory
  • Ensure Coreflux process has access
  • Verify STORAGE_DIR path is correct
  • Check disk space is available
  • Ensure directory is writable
  • Verify SOURCE_TOPIC matches incoming messages
  • Check QUERY syntax is correct
  • Verify APPEND is set correctly
  • Check MAX_RECORDS is set appropriately
  • Verify FILE_PATTERN includes {date} for daily rotation

Next Steps

Data Storage Routes Overview

Compare all storage options.

PostgreSQL Route

Configure PostgreSQL database storage.
Last modified on May 22, 2026