|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIG. - Google AI > 7. Helpers > AIG. - AI Google Gemini Integration |
MiniRobotLanguage (MRL)
AIG.FileToBase64
Encode a File's Content to Base64 String
Intention
FileToBase64 Command: Prepare Data for Transport
The FileToBase64 Command reads a binary file (such as an Image, PDF, or Audio file) from the disk and converts it into a Base64-encoded text string.
This transformation is required when sending multimodal data (non-text files) to the Google Gemini API using commands like AIG.AskVision.
It is a helper utility that abstracts the complexity of binary file reading and encoding. It uses an optimized, pointer-based internal encoder to handle large files (up to 20MB) efficiently without causing memory overflows or inserting unwanted line breaks (CRLF) that could break the JSON payload.
You need this command when manually constructing payloads or using lower-level API calls where you must provide the image data as a string.
�Data Embedding: JSON cannot store raw binary bits; they must be encoded as text.
�Custom Requests: If you are building your own JSON payload for special API endpoints.
�Debugging: To verify that a file can be read and encoded correctly before sending.
Simply provide the full path to the file you wish to encode. The command will return the resulting Base64 string into the specified variable (or on the TOS).
Example Usage
$$PAT=?exeloc\Samples\robot.png
' Encode the image
AIG.FileToBase64|$$PAT|$$B64
' Check length to ensure success
DBP.Encoded Length: $len($$B64)
Reads the file 'robot.png' and stores the encoded string in $$B64.
Illustration
+---------------+ � �+---------------------+
� Binary File � � -> � iVBORw0KGgoAAA... � �
+---------------+ � �+---------------------+
Converts raw bytes into a safe text string.
Syntax
AIG.FileToBase64|P1[|P2]
AIG.f2b|P1[|P2]
Parameter Explanation
P1 - (String) The full path and filename of the file to encode.
P2 - (Optional) Variable to store the resulting Base64 string. If omitted, result is on TOS.
Remarks
- This command does NOT validate if the file is a supported image type; it simply encodes whatever it reads.
- If the file does not exist, an error is set and an empty string is returned.
- Ideally suitable for files up to ~15MB. Very large files may cause memory pressure.
See also: