Loads a file from Object Storage Service (OSS) or an HTTP/HTTPS URL and returns the file content as bytea for downstream processing, such as Base64 encoding before passing to an AI model for inference.
Syntax
bytea AI_LoadFile (text url, integer buffer_limit)Parameters
| Parameter | Required | Description |
|---|---|---|
url | Yes | The path to the file. Accepts two formats: OSS path format or HTTP/HTTPS URL. For the OSS path format, see File path in OSS. |
buffer_limit | No | (Optional) The maximum file size to load, in MB. If the file exceeds this limit, the function returns an empty result. Set to 0 to remove the size limit. Default: 100. |
Return value
Returns the file content as bytea. Pass the result to a Base64 encoding function before sending it to an AI model for inference.
Examples
Load a file using the OSS path format
SELECT AI_LoadFile('OSS://<access_id>:<secret_key>@[<Endpoint>]/<bucket>/path_to/file');The Endpoint parameter is optional. If omitted, the system resolves the endpoint automatically, and the file path must start with a forward slash (/).
Endpoint specifies the OSS region node. Make sure your cluster and OSS are in the same region, and use the internal endpoint address. For endpoint details, see Use an endpoint that supports IPv6 to access OSS.
Load a file using an HTTP/HTTPS URL
The following example loads a file using an HTTP/HTTPS URL and limits the file size to 1 MB.
SELECT AI_LoadFile('http://oss-cn-hangzhou-internal.aliyuncs.com/my_bucket/my_folder/my_file', 1);