Upload SVG markup to Card Builder media
card_builder_upload_svgSanitize SVG markup and upload it to the Card Builder media directory, returning a reference URI. Use for publishing generated or hand-written SVG as media.
Instructions
Sanitize SVG markup and upload it to the Card Builder media directory.
svg_content must start with <svg or <?xml. .svg is appended to
filename if missing; the result is stored under
www/card_builder/<path>/<filename>. svg_content is always
sanitized first: <script>, <style>, <foreignObject>, <iframe>,
<embed>, <object> and other non-presentation elements are stripped
with their subtree, along with every on*= handler and any
href/xlink:href pointing at javascript: or an external/
data:image/svg+xml URL — see sanitize_svg for the allowlist. This
matters because the file becomes public, unauthenticated, under
/local/, where an unsanitized SVG opened directly executes embedded
script as stored XSS into an admin session. _write_media_file writes
with no existence check, so uploading onto an existing path/
filename silently overwrites it, with no backup.
Use when: publishing generated or hand-written SVG markup as media.
Not for: an SVG file on disk — use
card_builder_upload_media_from_path; a remote SVG URL — use
card_builder_upload_image_from_url.
Returns: {reference, path, url} — reference is the
cb-media://local/card_builder/<filename> URI for a block-image's
mediaReference prop.
Errors: {"error": "not_svg" | "file_too_large" | "path_not_allowed" | "svg_too_complex"} on invalid, unsafe, or oversized input.
Limits: capped at _MAX_MEDIA_UPLOAD_BYTES (15 MiB), then
_SVG_MAX_ELEMENTS elements after parsing.
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, e.g. 'gradient-bg'. '.svg' is appended if missing. | |
| svg_content | Yes | Raw SVG markup, starting with '<svg' or '<?xml ...'. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||