Upload media to Card Builder library
card_builder_upload_mediaUpload base64-encoded image bytes to the Card Builder media directory. Converts in-memory content into a public file and returns a reference for block-image use.
Instructions
Upload base64-encoded bytes as a file in the Card Builder media directory.
Decodes content_base64 and writes it under www/card_builder/<path>/ <filename> via card_builder/media/upload. filename must be a bare
name (no /, \, or ..) with an allowed extension — .png,
.jpg, .jpeg, .gif, .webp, .svg, .avif (case-insensitive). A
.svg filename gets its decoded content sanitized (script/handler/
unsafe-URL stripping, element-count cap) — see sanitize_svg. The
file becomes **public** under /local/ with **no authentication**,
same origin as the HA frontend. Upstream's _write_media_file writes
with no existence check, so uploading onto an existing filename/
path silently overwrites it, with no backup.
Use when: the file bytes are already in memory (e.g. generated inline).
Not for: a file already on the HA config filesystem — use
card_builder_upload_media_from_path; a remote image — use
card_builder_upload_image_from_url; raw SVG you'd rather not
base64-encode — use card_builder_upload_svg.
Returns: {reference, path, url} — reference is the
cb-media://local/card_builder/<filename> URI for a block-image's
mediaReference prop.
Errors: {"error": "extension_not_allowed" | "invalid_base64" | "file_too_large" | "invalid_svg" | ...} (plus sanitize_svg errors)
when validation or sanitization rejects the input.
Limits: decoded content over _MAX_MEDIA_UPLOAD_BYTES (15 MiB) is
refused.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Sub-folder under www/card_builder/ to upload into. Empty string uploads to the root. | |
| filename | Yes | Bare target filename with an allowed image/SVG extension, e.g. 'bg-1.png'. No path separators. | |
| content_base64 | Yes | Raw file bytes, base64-encoded. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||