Key Concepts
Helpers is a built-in utility function set designed to simplify file handling and data transformation in the Code Node (Python Node).
It can be used directly in the form of await helpers.function_name without any additional import.
It is mainly used to convert file data into the agentria standard format or to pass data between nodes.
File → Convert to base64
File → Extract mime-type
File → Convert to agentria standard format
Extract file metadata
Helpers Usage Example
file_type = await helpers.get_mime_type_from_file(file)
File Helpers
List of main helper functions related to file handling.
get_base64_str_from_file(bytes | str | list) -> strConverts file data into a base64 string and returns it.
get_mime_type_from_file(bytes | str | list) -> strExtracts the file's mime-type (e.g.,
image/png,application/pdf).
as_files(value, key, default_mime_type, immutable) -> list[str] | NoneConverts file data into the agentria standard file format (
data:mime;base64,...).
get_file_metadata(bytes | str | list) -> dictReturns file metadata (name, size, extension, type) as a dictionary.
as_files
Converts various types of file data into a standard format that can be used in agentria.
It is a core function frequently used when passing files within workflows or integrating with the Web Request Node.
async def as_files(
value: str | bytes | list | dict | None,
key: str | None = None,
default_mime_type: str = "application/octet-stream",
immutable: bool = True
) -> list[str] | None:
Supported Input Types
as_files(bytes_data): single file dataas_files(bytes_data, key="report.png"): single file with a specified file key (name)as_files([b1, b2]): list of multiple file dataas_files([("k1", b1), ("k2", b2)]): list of (key, file) tuplesas_files({"k1": b1, "k2": b2}): dictionary of key-value file pairs
Usage Examples
# 1. Convert a single image buffer into a usable file format in agentria
png_image_buffer = ...
from_buffer = await helpers.as_files(png_image_buffer)
# 2. Convert multiple image buffers
png_image_buffer_1 = ...
png_image_buffer_2 = ...
from_buffers = await helpers.as_files([png_image_buffer_1, png_image_buffer_2])
# 3. Specify form-data key when using Web Request Node
png_image_buffer = ...
from_buffer = await helpers.as_files({"file": png_image_buffer})
# Or
from_buffer = await helpers.as_files(png_image_buffer, key="file")
# 4. Using immutable option
# immutable=True: fixes the specified key
from_buffer = await helpers.as_files(png_image_buffer, key="dont_touch", immutable=True)
# immutable=False: allows the key name to be changed by the next node
from_buffer = await helpers.as_files(png_image_buffer, key="can_be_renamed", immutable=False)
Option Description
key : file key name used in form-data
default_mime_type : default value when mime-type cannot be determined
immutable : whether to fix the key (True: fixed, False: changeable)
get_file_metadata
Extracts detailed file information (metadata). It can be used for various purposes such as file validation, logging, and debugging.
Return Fields
Key | Description |
|---|---|
| MIME type of the file |
| File size (in bytes) |
| File name |
| File extension |