Skip to content

Read File

Summary

  • Internal name: ReadFile
  • Category: File System
  • Purpose: Read the text content of a file (up to 1 MB) into a workflow variable.
  • Task type: Normal

Compatibility

  • Minimum AndroMate version: 1.1.0

  • Maximum AndroMate version: 1.1.0

  • Minimum Android: Android 13 (API 33)

  • Maximum Android tested: Android 16 (API 36)

  • Required permissions: MANAGE_EXTERNAL_STORAGE


Detailed description

The Read File task reads the UTF-8 text content of a file and stores it in the value_output variable.

To protect device memory and avoid huge workflow variables, the file size is capped at 1 MB. A larger file is rejected with FILE-TASK-003 instead of being loaded. A workflow variable is meant for exploitable text (config, small JSON, results), not large files.

All File System tasks are confined to the AndroMate sandbox: /sdcard/AndromateFileTask. A path escaping the sandbox is rejected with FILE-TASK-001.

The content is returned as raw text, not parsed. To work with JSON afterwards, chain a JSON Object Operation task.


Input parameters

Parameter Type Required Possible values / Rules Android Compatibility AndroMate Compatibility Default
file_path String Yes File path inside the sandbox — max 1 MB Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 ""

Output parameters

Field Type Trigger condition Android Compatibility AndroMate Compatibility Default
value_output String On success — the file text content Android 13 (API 33) → Android 16 (API 36) 1.1.0 → 1.1.0 <ANDROMATE_NULL_VALUE>

Exceptions

Code Trigger condition
FILE-TASK-001 Path is outside the AndroMate sandbox
FILE-TASK-002 File system operation failed (e.g. file not found)
FILE-TASK-003 File too large to read (over 1 MB)

Execution flowchart

flowchart TD
    Start([▶ ReadFile]) --> Jail[📂 Ensure sandbox exists]

    Jail --> Validate{Path inside sandbox ?}

    Validate -->|No| ThrowJail([❌ FILE-TASK-001])
    Validate -->|Yes| Size{Size <= 1 MB ?}

    Size -->|No| ThrowBig([❌ FILE-TASK-003])
    Size -->|Yes| Read[📖 readText UTF-8]

    Read --> Store[💾 Set value_output]

    Store --> Success([✅ StrTaskResult])

    style Start fill:#e3f2fd
    style Success fill:#c8e6c9
    style ThrowJail fill:#ffcdd2
    style ThrowBig fill:#ffcdd2
    style Read fill:#f3e5f5
    style Store fill:#c8e6c9

How it works:

  1. Sandbox: the sandbox directory is created if missing
  2. Validate: the resolved path is checked to be inside the sandbox
  3. Size guard: if the file is larger than 1 MB, throws FILE-TASK-003
  4. Read: the file is read as UTF-8 text
  5. Store: the content is written to value_output
  6. Result: returns StrTaskResult

Code examples

Example 1 — Read a config file into a variable

{
  "ReadFile": [
    {
      "id": "1",
      "title": "Read config",
      "file_path": "config.json",
      "value_output": "$config"
    }
  ]
}

Example 2 — Read then parse JSON

{
  "ReadFile": [
    {
      "id": "1",
      "title": "Read data",
      "file_path": "data.json",
      "value_output": "$raw_json"
    }
  ]
}

(then use a JSON Object Operation task on $raw_json)


Input parameter details

file_path — File to read

Path inside the sandbox. The file must not exceed 1 MB or the task throws FILE-TASK-003. Supports $variable interpolation.


Output parameter details

value_output — File content

Stores the raw UTF-8 text content of the file in the specified workflow variable. The content is not parsed — use a JSON Object Operation task to process structured data.


Complete JSON example

{
  "ReadFile": [
    {
      "id": "1",
      "title": "Read File",
      "file_path": "logs/result.log",
      "value_output": "$FILE_CONTENT"
    }
  ]
}