All Products
Search
Document Center

PolarDB:AI_LoadFile

Last Updated:Mar 28, 2026

Loads a file from Object Storage Service (OSS) and returns its content as binary data.

Syntax

bytea AI_LoadFile(text url, integer buffer_limit)

Parameters

ParameterDescription
urlThe path to the OSS file. Supported formats:
  • OSS: the OSS file path format. For more information, see .
  • HTTP/HTTPS: a URL such as http://oss-cn-hangzhou-internal.aliyuncs.com/my_bucket/my_folder/my_file.
buffer_limitThe 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 value: 100.

Return values

Returns the file content in bytea format.

Usage notes

Use AI_LoadFile to load a file from OSS into memory for further processing — for example, encoding the content in Base64 before passing 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 automatically identifies the endpoint, and the file path must start with a forward slash (/).

Note

The Endpoint specifies the OSS region node. Make sure your cluster and OSS bucket are in the same region, and use the internal endpoint address to access OSS. For more information, see Use an endpoint that supports IPv6 to access OSS.

Load a file using an HTTP/HTTPS URL with a 1 MB size limit

SELECT AI_LoadFile('http://oss-cn-hangzhou-internal.aliyuncs.com/my_bucket/my_folder/my_file', 1);