Skip to main content

general

OPC UA File Operation Node

Perform read and write operations on OPC UA File objects that implement the FileType interface (ns=0;i=11575).

This node enables interaction with files stored on OPC UA servers, supporting various read/write modes, encoding options, and output formats.

Configuration

NodeId

  • Required: The NodeId must reference an Object node with TypeDefinition = FileType
  • Input: Can be configured in the node or provided dynamically via msg.nodeId
  • Format: Supports standard NodeId formats (ns=X;i=Y) and browse paths (/ns1:FolderDemo/ns1:file.txt)

Mode

Select the operation to perform:

  • Read: Reads the complete file content from the OPC UA server
  • ReadSize: Returns only the file size in bytes without reading content
  • Write: Writes data to the file (equivalent to WriteEraseExisting)
  • WriteEraseExisting: Overwrites the entire file with new content
  • WriteAppend: Appends data to the end of the existing file

Encoding (Read/Write)

Controls character encoding for text files:

  • none: Raw binary data (default)
  • setbymsg: Use encoding specified in msg.encoding
  • utf8, ascii, utf-16le: Unicode encodings
  • Shift_JIS, EUC-JP: Japanese encodings
  • GB2312, GBK, Big5: Chinese/Taiwan encodings
  • Plus many other regional encodings (Windows, ISO, IBM, Mac, KOI8)

Format (Read only)

Output format for read operations:

  • buffer: Returns raw Buffer object (default)
  • utf8: Returns decoded string using specified encoding
  • lines: Returns array of strings, split by newline characters

Input Message

Read Operations

msg = {
nodeId: "ns=1;s=MyFile" // Optional, overrides configured NodeId
encoding: "utf8" // Optional, when encoding="setbymsg"
}

Write Operations

msg = {
payload: "content to write", // String, Buffer, or JSON object
nodeId: "ns=1;s=MyFile", // Optional, overrides configured NodeId
encoding: "utf8" // Optional, when encoding="setbymsg"
}

Write Payload Types:

  • String: Written directly (with optional encoding)
  • Buffer: Written as binary data
  • Object/Array: Automatically JSON.stringify'd
  • Boolean/Number: Converted to string

Output Message

Read Mode

msg = {
payload: <Buffer|string|string[]> // Based on format setting
}

ReadSize Mode

msg = {
payload: 12345 // File size in bytes
}

Write Modes

msg = {
size: 12345 // Number of bytes written
}

How It Works

Read Process:

  1. Opens the OPC UA File object
  2. Reads content in optimized chunks (respects server MaxByteStringLength)
  3. Automatically handles large files using streaming
  4. Applies encoding/format conversion if specified
  5. Returns formatted output

Write Process:

  1. Extracts and encodes data from msg.payload
  2. Opens file in specified mode (Write/Append)
  3. Splits data into chunks based on transport limits
  4. Writes chunks sequentially to server
  5. Returns final file size

Performance Optimization:

  • Chunk size automatically calculated based on:
    • Server's MaxByteStringLength capability
    • Transport maxMessageSize settings
    • Hard limit of BinaryStream.maxByteStringLength
  • Streaming architecture handles files larger than memory

Node Status

  • Operating: Reading/writing in progress
  • size = X: Operation completed successfully (X bytes)
  • failed: Operation error (check debug panel)

Examples

Read Text File

// Configure: Mode=Read, Format=utf8, Encoding=utf8
// Input: trigger inject
// Output: msg.payload = "file contents as string"

Read CSV as Lines

// Configure: Mode=Read, Format=lines, Encoding=utf8
// Input: trigger inject
// Output: msg.payload = ["line1", "line2", "line3"]

Write JSON Data

// Configure: Mode=Write, Encoding=utf8
msg.payload = { temperature: 25.5, timestamp: Date.now() };
// Result: JSON string written to file

Append Log Entry

// Configure: Mode=WriteAppend, Encoding=utf8
msg.payload = "2025-11-24 12:00:00 - New log entry\n";
// Result: Appended to existing file

Check File Size

// Configure: Mode=ReadSize
// Input: trigger inject
// Output: msg.payload = 4096 (bytes)

Dynamic NodeId

// Configure: NodeId = (leave empty)
msg.nodeId = "/ns1:Logs/ns1:system.log";
// Read/write operation uses runtime-specified file

Error Handling

Common errors:

  • "nothing to write": msg.payload is undefined/empty
  • "expecting a nodeIdString": Invalid nodeId format
  • Failed status: Node error contains specific OPC UA status code

Tips

  1. Large Files: Node automatically handles chunking - no size limits beyond server capabilities
  2. Text Files: Use encoding="utf8" and format="utf8" for best results
  3. Binary Files: Use encoding="none" and format="buffer" for images, executables, etc.
  4. CSV Processing: Use format="lines" to get array of rows for easy parsing
  5. Dynamic Files: Pass nodeId in msg for runtime file selection
  6. Append Mode: Ideal for logging scenarios where existing data must be preserved
  • OpcUa-Client2-Browse: Discover available File objects on the server
  • OpcUa-Client2-Read: Read file metadata properties (Size, OpenCount, UserWritable)
  • OpcUa-Client2-Call: Call file methods (GetPosition, SetPosition, etc.)