Converts binary image data into a Base64-encoded string.
Syntax
AI_ImageAsBase64(bytea image, boolean mime_type DEFAULT true)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
image | bytea | — | The image data in binary format. |
mime_type | boolean | true | Specifies whether to include a Multipurpose Internet Mail Extensions (MIME) type prefix in the output string. Valid values: true (default): The returned string starts with data: followed by the image's MIME type. For example: data:image/jpeg;base64,xxxxx. false: Returns only the Base64-encoded image data, without any MIME type prefix. For more information about MIME types, see MDN Web Docs: data URLs. |
Return value
Returns a Base64-encoded string representation of the input image.
Usage notes
Supported image formats: JPEG, PNG, and BMP.
AI models typically have size constraints on input images. If your source image has high pixel dimensions that exceed the model's limit, use AI_ResizeImage to resize it before calling this function.
Example
SELECT AI_ImageAsBase64(data) FROM ai_image_test WHERE id = 1;Sample output:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD...