:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(canvas): support public media images (#93202)
Harley Alexanderc8c5841e6714
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 5e19251f4563..1119192d5b3f 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -5298,6 +5298,7 @@ export type UploadedMediaListParams = {export type UploadedMediaListPurpose = (typeof UploadedMediaListPurpose)[keyof typeof UploadedMediaListPurpose]export const UploadedMediaListPurpose = {+ Canvas: 'canvas',Email: 'email',} as const@@ -5309,6 +5310,7 @@ export type UploadedMediaCreateBodyPurpose =export const UploadedMediaCreateBodyPurpose = {Email: 'email',+ Canvas: 'canvas',} as constexport type UploadedMediaCreateBody = {diff --git a/frontend/src/generated/core/api.zod.ts b/frontend/src/generated/core/api.zod.tsindex 58fed89e56d7..0dd802a2414b 100644--- a/frontend/src/generated/core/api.zod.ts+++ b/frontend/src/generated/core/api.zod.ts@@ -1024,7 +1024,7 @@ export const SessionRecordingsSharingRefreshCreateBody = /* @__PURE__ */ zodexport const UploadedMediaCreateBody = /* @__PURE__ */ zod.object({image: zod.instanceof(File).describe('Image file. Must be under 4MB and a real, decodable image.'),purpose: zod- .enum(['email'])+ .enum(['email', 'canvas']).optional().describe('Library to add this image to. Omit to upload without joining a library (as dashboard text cards and notebooks do).'diff --git a/posthog/api/test/test_uploaded_media.py b/posthog/api/test/test_uploaded_media.pyindex 3067cdbec59e..4b7465e1dfbb 100644--- a/posthog/api/test/test_uploaded_media.py+++ b/posthog/api/test/test_uploaded_media.py@@ -326,17 +326,17 @@ class TestMediaLibraryAPI(APIBaseTest):assert UploadedMedia.objects.count() == 0def test_list_returns_only_matching_purpose_for_own_team_newest_first(self) -> None:- first = self._create_media(purpose="email", file_name="first.png")- second = self._create_media(purpose="email", file_name="second.png")+ first = self._create_media(purpose="canvas", file_name="first.png")+ second = self._create_media(purpose="canvas", file_name="second.png")self._create_media(purpose=None, file_name="legacy-dashboard-image.png")self._create_media(purpose="something-else", file_name="other-purpose.png")other_team = Team.objects.create(organization=self.organization, name="other team")UploadedMedia.objects.create(- team=other_team, file_name="not-mine.png", content_type="image/png", purpose="email"+ team=other_team, file_name="not-mine.png", content_type="image/png", purpose="canvas")- response = self.client.get(f"/api/projects/{self.team.id}/uploaded_media/?purpose=email")+ response = self.client.get(f"/api/projects/{self.team.id}/uploaded_media/?purpose=canvas")self.assertEqual(response.status_code, status.HTTP_200_OK, response.json())payload = response.json()@@ -346,7 +346,7 @@ class TestMediaLibraryAPI(APIBaseTest):listed = payload["results"][0]assert listed["name"] == "second.png"assert listed["content_type"] == "image/png"- assert listed["purpose"] == "email"+ assert listed["purpose"] == "canvas"assert listed["url"] == f"http://localhost:8010/uploaded_media/{second.id}"assert listed["created_at"] is not None@@ -414,7 +414,7 @@ class TestMediaLibraryAPI(APIBaseTest):with self.settings(OBJECT_STORAGE_ENABLED=True, OBJECT_STORAGE_MEDIA_UPLOADS_FOLDER=TEST_BUCKET):response = self.client.post(f"/api/projects/{self.team.id}/uploaded_media/start_upload/",- {"name": "logo.png", "purpose": "email"},+ {"name": "logo.png", "purpose": "canvas"},)self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.json())payload = response.json()@@ -424,7 +424,7 @@ class TestMediaLibraryAPI(APIBaseTest):media = UploadedMedia.objects.get(id=payload["id"])assert media.pending is True- assert media.purpose == "email"+ assert media.purpose == "canvas"assert media.team_id == self.team.pkdef test_start_upload_requires_name_and_purpose(self) -> None:diff --git a/posthog/models/uploaded_media.py b/posthog/models/uploaded_media.pyindex 8ec099d08069..d268a041a43f 100644--- a/posthog/models/uploaded_media.py+++ b/posthog/models/uploaded_media.py@@ -26,7 +26,8 @@ class ObjectStorageUnavailable(Exception):# line here, but the API accepts nothing outside this set: a typo would otherwise open a# second library that nothing lists, and give the caller no sign that it had.MEDIA_PURPOSE_EMAIL = "email"-MEDIA_PURPOSES = [MEDIA_PURPOSE_EMAIL]+MEDIA_PURPOSE_CANVAS = "canvas"+MEDIA_PURPOSES = [MEDIA_PURPOSE_EMAIL, MEDIA_PURPOSE_CANVAS]# A pending row older than this is abandoned: the presigned URL it was created for expires in# minutes, so nothing can complete it, and nothing else revisits it. Generous because the onlydiff --git a/products/canvas/skills/building-canvases/SKILL.md b/products/canvas/skills/building-canvases/SKILL.mdindex a3c16684721d..c988d769220b 100644--- a/products/canvas/skills/building-canvases/SKILL.md+++ b/products/canvas/skills/building-canvases/SKILL.md@@ -67,6 +67,25 @@ graphics code owns a canvas element, or a mostly static page can mount one interThis is a judgment call, not a persisted mode — ask the user only when the choice changes auser-visible requirement you cannot infer.+## Images++Use public media library URLs for images in a canvas. Call `posthog:media-images-list` with+`purpose="canvas"` first and reuse a suitable image when one already exists.++To add a local image:++1. Call `posthog:media-image-upload-start` with the file name and `purpose="canvas"`.+2. From a shell, POST the file to the returned `upload_url` as multipart form data. Include every+ returned `form_fields` entry and put the file part last.+3. Call `posthog:media-image-upload-complete` with the returned id and use its permanent `url` as+ the image `src`.+4. Add the URL's exact origin to `project.capabilities.network.origins`. Canvas validation checks+ this declaration, and the published artifact uses it in its Content Security Policy.++Canvas media URLs are public and do not require authentication. Never upload secrets, credentials,+customer data, or sensitive screenshots. Images must be under 4 MB and decode as PNG, JPEG, GIF,+WebP, AVIF, or BMP. Never base64-encode image bytes into a tool call.+## Common request patternsUse these as routing examples, not fixed templates:@@ -150,7 +169,8 @@ That field is the only valid link to a canvas — never construct one yourself;relative TypeScript, TSX, JavaScript, JSON, SVG, CSS, and admitted asset files from the project.- Self-contained module workers may be imported with `./worker.ts?worker`. A worker must not importanother local module.-- Binary assets belong in the project's `assets` map as base64 content with an admitted content type.- PNG, JPEG, GIF, WebP, AVIF, WOFF/WOFF2, WebAssembly, and generic octet-stream assets are supported.+- Use the public media library flow above for images. Other binary assets belong in the project's+ `assets` map as base64 content with an admitted content type. WOFF/WOFF2, WebAssembly, and generic+ octet-stream assets are supported.- Keep the platform dependency map exactly as returned. Do not add npm packages; local relativeimports are project files, while bare imports remain limited to the platform-pinned set.diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 47870cd5ebb8..acd905707cdc 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -100049,6 +100049,7 @@ export namespace Schemas {export const UploadedMediaListPurpose = {+ Canvas: 'canvas',Email: 'email',} as const;@@ -100060,6 +100061,7 @@ export namespace Schemas {export const UploadedMediaCreateBodyPurpose = {Email: 'email',+ Canvas: 'canvas',} as const;export type UploadedMediaCreateBody = {diff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.tsindex c02d8700590f..ae3f76a1578f 100644--- a/services/mcp/src/generated/core/api.ts+++ b/services/mcp/src/generated/core/api.ts@@ -2685,7 +2685,7 @@ export const UploadedMediaListParams = () => zod.object({export const UploadedMediaListQueryParams = () => zod.object({limit: zod.number().optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),- purpose: zod.enum(['email']).describe('The library to list.'),+ purpose: zod.enum(['canvas', 'email']).describe('The library to list.'),})/**diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/media-images-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/media-images-list.jsonindex cadcd6009140..af95fdc70362 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/media-images-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/media-images-list.json@@ -11,7 +11,7 @@},"purpose": {"description": "The library to list, e.g. \"email\". Required.",- "enum": ["email"],+ "enum": ["canvas", "email"],"type": "string"}},