Skip to main content

File Write Action (File Writer)

The File Write Action writes content from workflow memory to files and supports both overwriting and appending to existing files.

What does this integration do?

The File Write Action takes data from workflow memory and writes it to files in the filesystem. It can create new files, overwrite existing ones, or append content to existing files. Complex data structures are automatically formatted as JSON.

Typical Use Cases:

  • Report Generation: Storing reports and analyses as files
  • Data Export: Export of processed data in various formats
  • Log Files: Creation and maintenance of application logs
  • Configuration Files: Automatic generation of config files
  • Backup Creation: Backup of workflow results
  • Template Output: Storage of generated documents and templates

User Configuration

File Configuration

File Path (File Path)

  • Purpose: Full path of the file to be written
  • Format: Absolute or relative path
  • Directory Creation: Parent directories are automatically created
  • Examples:
    • /data/reports/daily_report.txt
    • ./output/processed_data.json
    • C:\\Output\\Results\\summary.csv
    • /tmp/workflow_{{timestamp}}.log

Encoding (Character Encoding) - Optional

  • Purpose: Character encoding for the file
  • Default: utf8
  • Options: utf8, ascii, latin1, base64, etc.
  • Usage: Special encoding for specific file formats

Content (Content)

  • Purpose: Variable name containing the content to be written
  • Data Source: Variable from previous workflow steps
  • Data Types: String, JSON objects, arrays
  • Examples: reportData, processedResult, generatedContent

Append (Append) - Optional

  • Purpose: Determines whether content is appended to existing file
  • Default: false (overwrite file)
  • Options:
    • false - Overwrite file or create new
    • true - Append content to existing file

How it Works

Data Processing

Content Transformation:

  • String data is written directly
  • Objects/arrays are automatically formatted as JSON
  • Pretty-print JSON with 2-space indentation

Append Mode:

  • Check if file already exists
  • Load existing content
  • Append new data

Error Handling:

  • Automatic directory creation
  • Robust error handling for filesystem problems
  • Detailed logging for debugging

Workflow Integration

Datentypen

String Content:

Variable: reportText
Content: "Daily Report\n=============\n\nSales: 1250€\nOrders: 45\n"

Result File:
Daily Report
=============

Sales: 1250€
Orders: 45

JSON-Objekt:

Variable: analysisData
Content: {
"summary": "Analysis complete",
"results": [
{"metric": "conversion", "value": 0.85},
{"metric": "revenue", "value": 15420}
],
"timestamp": "2024-03-15T10:30:00Z"
}

Result File (formatted JSON):
{
"summary": "Analysis complete",
"results": [
{
"metric": "conversion",
"value": 0.85
},
{
"metric": "revenue",
"value": 15420
}
],
"timestamp": "2024-03-15T10:30:00Z"
}

Integration mit anderen Actions

Mit LLM Action:

1. LLM Action generiert Bericht
Output: generatedReport

2. File Write Action speichert
Content: generatedReport
File Path: /reports/{{reportDate}}.md

Mit HTTP Action:

1. HTTP Action holt Daten
Output: apiData

2. File Write Action exportiert
Content: apiData
File Path: ./exports/data_{{timestamp}}.json

Practical Examples

Daily Report

Konfiguration:

  • File Path: /reports/daily/report_{{currentDate}}.txt
  • Encoding: utf8
  • Content: dailyReport
  • Append: false

Example Content (dailyReport):

=== DAILY BUSINESS REPORT ===
Date: 2024-03-15

Sales Summary:
- Total Revenue: 15,420.50 €
- Number of Orders: 127
- Average Order Value: 121.42 €

Top Products:
1. Product A: 45 units
2. Product B: 32 units
3. Product C: 28 units

Customer Metrics:
- New Customers: 23
- Returning Customers: 104

Log File Creation

Konfiguration:

  • File Path: /var/log/workflow.log
  • Content: logEntry
  • Append: true

Example Content (logEntry):

[2024-03-15 10:30:15] INFO: Workflow started - ID: WF-12345
[2024-03-15 10:30:18] INFO: Data processing completed - 1250 records
[2024-03-15 10:30:22] INFO: Email notifications sent - 45 recipients

JSON Data Export

Konfiguration:

  • File Path: ./exports/customer_data_{{exportId}}.json
  • Content: customerExport
  • Append: false

Example Content (customerExport):

{
"export_info": {
"timestamp": "2024-03-15T10:30:00Z",
"total_records": 1250,
"export_type": "full"
},
"customers": [
{
"id": 12345,
"name": "Max Mustermann",
"email": "max@example.com",
"last_order": "2024-03-10T14:30:00Z"
}
]
}

CSV Report Generation

Konfiguration:

  • File Path: /data/analytics/sales_{{month}}.csv
  • Content: csvReport

Example Content (csvReport):

Date,Product,Quantity,Revenue
2024-03-01,Product A,45,1125.00
2024-03-01,Product B,32,960.00
2024-03-02,Product A,38,950.00
2024-03-02,Product C,28,840.00

Configuration File Creation

Konfiguration:

  • File Path: /etc/app/generated_config.yml
  • Content: configYaml

Example Content (configYaml):

database:
host: db.company.com
port: 5432
name: production_db

api:
endpoint: https://api.company.com/v1
timeout: 30000

features:
analytics: true
reporting: true
alerts: false

Technical Details

Schema Configuration

configSchema: {
filePath: {
name: 'File Path',
schema: z.string()
},
encoding: {
name: 'Encoding',
schema: z.string().optional()
},
content: {
name: 'Content',
reference: 'memory-in',
schema: z.string(),
},
append: {
name: 'Append',
description: 'Append to file instead of overwrite',
schema: z.boolean().optional(),
},
}

Internal Implementation

Filesystem Integration:

  • Uses FilesystemStorageService for secure file operations
  • Automatic directory creation for new paths
  • Robust error handling for filesystem problems

Data Serialization:

  • Automatic JSON formatting for objects/arrays
  • Preservation of string data without changes
  • Pretty-print JSON for better readability

Append Functionality:

  • Check file existence before append
  • Safe loading and merging of content
  • Atomic write operations where possible

Best Practices

File Path Management

Path Structure:

  • Use logical directory structures
  • Implement naming conventions with timestamps
  • Avoid spaces and special characters in paths

Permissions:

  • Ensure write permissions are available
  • Use secure directories for sensitive data
  • Implement cleanup strategies for temporary files

Performance

Datei-Größen:

  • Begrenzen Sie Dateigröße für bessere Performance
  • Verwenden Sie Rotation für große Log-Dateien
  • Implementieren Sie Compression für Archiv-Dateien

Append-Optimierung:

  • Verwenden Sie Append für Log-Dateien und kontinuierliche Daten
  • Vermeiden Sie Append bei großen bestehenden Dateien
  • Implementieren Sie Datei-Rotation bei kritischen Größen

Sicherheit

Pfad-Validierung:

  • Validieren Sie Dateipfade gegen Path-Traversal-Angriffe
  • Beschränken Sie Schreibzugriff auf autorisierte Verzeichnisse
  • Implementieren Sie Dateigrößen-Limits

Daten-Sicherheit:

  • Verschlüsseln Sie sensitive Daten vor dem Schreiben
  • Verwenden Sie sichere Dateiberechtigungen
  • Implementieren Sie Audit-Logging für Dateierstellung

Wartung

Monitoring:

  • Überwachen Sie Dateisystem-Speicherplatz
  • Tracken Sie Datei-Schreibfehler
  • Implementieren Sie Alerts für kritische Verzeichnisse

Cleanup:

  • Implementieren Sie automatische Datei-Archivierung
  • Verwenden Sie Retention-Policies für Log-Dateien
  • Überwachen Sie Verzeichnisgrößen

The File Write Action extends Vectense Platform with robust filesystem integration and enables persistent storage of workflow results.