|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > HTP. - Command > !HTP-General - General HTTP operations and utilities > !Utility - Helper functions for HTTP operations (string conversion, proxy toggling) > HTP. - HTTP Operations |
SPR Script Language
HTP.ToBase64File
Reads a file, encodes its content to Base64, and streams the result to an output file.
Intention
The HTP.ToBase64File command is designed to handle the Base64 encoding of large files without consuming excessive memory. It reads the input file in chunks, encodes each chunk, and writes the result directly to the output file. This streaming approach makes it highly efficient for preparing large binary files (like high-resolution images or audio) for embedding in JSON payloads or for other transport mechanisms.
The command returns a simple success (1) or failure (0) code, making it easy to verify the operation's outcome in a script.
Syntax
HTP.ToBase64File|$$INP|$$OUT[|$$RET]
Parameter Explanation
P1 - $$INP - (Variable, String, Required)
The full path to the input file that you want to encode.
P2 - $$OUT - (Variable, String, Required)
The full path where the resulting Base64 text file will be saved. If the file exists, it will be overwritten.
P3 - $$RET - (Variable, String, Optional)
An optional variable to store the result code (1 for success, 0 for failure).
Examples
'***********************************
' HTP.ToBase64File - Sample 1: Encode an image to a text file
'***********************************
VAR.$$INP=?path\my_image.png
VAR.$$OUT=?path\my_image_base64.txt
HTP.ToBase64File|$$INP|$$OUT|$$RES
JIZ.$$RES|Lab_failed
MBX.Success:|File $$INP was successfully encoded to $$OUT.
END.
Remarks
- The resulting file will contain a single, continuous line of Base64 text without any line breaks.
- On failure, an error is set in the HTP library. Use HTP.GetErr to retrieve a descriptive error message.
See also: