All Products
Search
Document Center

PolarDB:AI_LoadFile

Last Updated:Apr 21, 2025

Loads a file from Object Storage Service (OSS).

Syntax

bytea AI_LoadFile (text url, integer buffer_limit)

Parameters

Parameter

Description

url

The path to the OSS file. Valid formats:

  • OSS: the OSS file path format. For more information, see File path in OSS.

  • HTTP/HTTPS: the HTTP or HTTPS URL format, such as http://oss-cn-hangzhou-internal.aliyuncs.com/my_bucket/my_folder/my_file.

buffer_limit

The maximum allowable size for the file to be loaded. Unit: MB. If the file size exceeds the value, the function returns an empty result. A value of 0 indicates that no limit is imposed on the file size. Default value: 100.

Return values

The function returns the content of the loaded file in the bytea format.

Description

The function loads a file from a specified URL and returns the file content in the bytea format. You can use the function to load files into memory for further processing. For example, you can encode the files by using Base64 and then pass the files to an AI model for interference.

Examples

  • Load a file from OSS by using the OSS address of the file.

    SELECT AI_LoadFile('OSS://<access_id>:<secrect_key>@[<Endpoint>]/<bucket>/path_to/file');

    The Endpoint parameter is optional and can be omitted. If you do not specify the Endpoint parameter, the system automatically identifies the endpoint and you must start the file path with a forward slash (/).

    Note

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

  • Load a file from OSS by using the HTTP/HTTPS URL of the file and limit the file size to 1 MB.

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