All Products
Search
Document Center

PolarDB:AI_ImageAsBase64

Last Updated:Sep 22, 2026

Converts an image to a Base64 string.

Syntax

text AI_ImageAsBase64 (bytea image, boolean mime_type DEFAULT true)

Parameters

Parameter

Description

image

The image data represented in binary format.

mime_type

The MIME type. Valid values:

  • true (default): The returned Base64 string starts with data: followed by the MIME type of the image. For example: data:image/jpeg;base64,xxxxx, which indicates JPEG format.

  • false: The returned Base64 string does not include a MIME type prefix.

Note

For more information about MIME types, see community documentation.

Return value

Returns the Base64 string of the converted image.

Description

  • JPEG, PNG, and BMP image formats are supported.

  • AI models typically have specific size requirements for input images, but common images tend to have large pixel dimensions. You can use the AI_ResizeImage function to resize the image to the required dimensions, and then use this function to convert it to a Base64 string.

Example

SELECT AI_ImageAsBase64(data) FROM ai_image_test WHERE id = 1;

Sample output:

---
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD...