Something Else

cms-edit · Eagle Capital

← All playbooks · Raw API

task-media-reuse-and-upload

# Capability: Media — reuse and upload

## Intent phrases

- upload image
- find existing asset
- add photo to page or article
- update person headshot / portrait

## Requires capabilities

`assetSearch` and `assetUpload`

## Prerequisites

- **Always run `index sync` first** if the catalog may be stale
- On **hosted MCP**, the server has **no filesystem** — use **staged upload** for all binary uploads (never `--base64` or a local file path in `args`)

## Reuse-first workflow (default)

1. `cms_edit ["index", "sync"]`
2. **Search existing assets:**
   - `cms_edit ["asset", "search", "--filename-match", "<partial-name>"]`
   - `cms_edit ["list", "--type", "media", "--asset-filename-match", "<partial>"]`
3. If match found — link by asset ID or filename in `set` / `create from-json` (`featuredImageAssetFilename`, `visualAssetFilename`, etc.)
4. For **`visuals`** (Media entry **array** on page/article): prefer an **existing Media entry** — `cms_edit ["list", "--type", "media", "--asset-id", "<assetId>"]` — then `set @root visuals <mediaEntryId> --links`. Do **not** `create media` or use `asset upload --with-media` when a wrapper already exists.
5. For **singular** component fields (e.g. `visual` on a component):  
   `cms_edit ["set", "@cN", "visual", "<mediaEntryId>", "--link"]`  
   **Never** `add media --parent @cN --target visual` — `add --target` only works for Entry-link **arrays** (`content`, `contents`, …). Bad `add --target` is rejected; it used to orphan Media drafts.
6. `create media` only when no Media entry wraps that asset (RTF embeds, or first article in a new composite batch — then **reuse that media ID** on sibling entries)
7. Bare Contentful entry IDs work with `set` (no `@` required) for mid-session Media field tweaks (width/autoplay/loop) after import — `set <mediaEntryId> width 75`.

## Upload only when no match

### Raster images and video (required)

Encode via **`task-media-pipeline-prepare`**. Intake can be:

1. A **Drive folder**, or
2. **Staged upload**: `cms_edit_request_staged_upload` → curl → follow `consumeArgs`, or
3. **httpsUrls** on pipeline-allowed hosts

Then wait → catalog → **import** with `overrides[].alt` for a **new** asset. Do **not** `asset upload --staged/--base64` for jpeg/png/webp/gif/mp4. Do **not** `asset upload --url` for **video** (import only). Raster `--url` only for pipeline ready image hosts.

**Search before upload still applies.** `asset search` (title or file name) first. **Search by concept** is how an editor finds a subject and a tone, including files no page uses yet:

```
cms_edit ["asset", "search", "--concept", "<subject-concept-id>", "--concept-all", "<tone-concept-id>"]
```

`--concept` matches any listed id. Repeat `--concept-all` when several concepts are required. The result is id, title, file name, description, concepts. Concept search reads Contentful. It does not use the local index.

**Size.** Video source intake is **100MB** via direct-to-storage. An image master over **4MB** uses the same path. JSON, text, SVG, PDF, and Lottie stay on the **4MB** function POST. Pass `byteLength` for an image that might be over 4MB so the tool returns a presigned PUT (`intake: "direct"`) instead of the function URL. Run the curl, then `consumeArgs` (`media prepare --https-urls` of the public intake URL). The asset stored in Contentful is the **processed** file from the pack (`…/packs/…/ready/…`), not the 100MB source. Do not re-encode every asset. Size targets come from the site sizing standard. `asset review` still flags a stored video over **8MB**.

**Replace the file on an existing id** when pages already point at it. A second upload leaves those links on the old id.

```
cms_edit ["asset", "replace", "<asset-id>", "--url", "<processed-ready-url>", "--dry-run"]
cms_edit ["asset", "replace", "<asset-id>", "--url", "<processed-ready-url>"]
```

Replace keeps the id and the current file name. Dry-run returns id, file name, old dimensions, new dimensions, and writes nothing. The write is a draft. There is no publish flag. It refuses a replace that would turn an image into a non-image, or the reverse. SVG, PDF, and Lottie may use `--staged` or `--url`. Raster and video must use the processed pack URL.

**Title.** `asset set-title <asset-id> "<title>"` sets the asset title. Draft. It does not change the file name. Description stays `asset set-description`, written from the picture.

**Concepts are not blog tags.** `taxonomy-from-json` stays the blog importer (`tag` / `tagType`). Do not turn `taxonomyImport` on. Asset concepts are Contentful `metadata.concepts`, assigned by concept id after a person creates the scheme in the Taxonomy manager. The same organisation concepts show in every space. Files do not cross spaces. cms-edit does not create the scheme.

```
cms_edit ["asset", "concept", "assign", "<asset-id>", "<concept-id>"]
cms_edit ["asset", "concept", "unassign", "<asset-id>", "<concept-id>"]
```

A missing concept fails with the id. Do not invent one.

**Do not emotion-score headshots, logos, icons, or illustrations.** Tone concepts are for lifestyle photos only. Alt text is still the asset description, one sentence from looking at the picture, not a keyword list and not the file name.

Animated GIFs become **MP4** (`gif-converted`) — attach as mute-loop Media / video visual, not `featuredImage`. **Do not** convert the GIF (or PNG) with local ffmpeg first; prepare the original file. If prepare gaps say `staged GET failed 405`, stop and report a cms-edit host bump — do not retry and do not use the Contentful web UI. If they say `staged GET failed 404`, re-stage (POST) and prepare once — the GET route exists.

### SVG, PDF, Lottie

These may skip the pipeline. On hosted MCP use staged upload then `asset upload --staged`.

### Hosted MCP

**Always use staged upload** for ad-hoc binaries. Do not pass base64 in `cms_edit` args — hosted MCP rejects `asset upload --base64`.

1. `cms_edit_request_staged_upload` with `fileName`, `mimeType`, `byteLength` when the file may be over 4MB, optional `title`
2. Run the returned `curlCommand`. `intake: "direct"` (video, or an image over 4MB) is a PUT of the file. `intake: "function"` is a POST to `uploadUrl`. Do not POST a video through the function.
3. Follow `consumeArgs`. Direct intake: **media prepare** with `--https-urls` / `httpsUrls`. Function intake of an image at or under 4MB: **media prepare** with `stagedUploadIds`. SVG/PDF/Lottie: **asset upload --staged**.

Rules:

- Staged upload keeps binary **out of MCP args**
- Function POST (JSON, text, SVG, PDF, Lottie, and an image at or under 4MB): **4 MB**. Video, and an image master over 4MB: **100MB** presigned PUT to storage, then the media pipeline. **1000 upload URLs per user per hour**; TTL **60 minutes**
- Direct intake bytes are not stored in Redis. An image at or under 4MB stays in Redis until the pipeline fetches it (GET). Neither path writes the source to CMA
- Upload/import alone does **not** attach the asset — follow with **link + save** (below)
- Use `--if-exists-by-filename` (with `--file-name`) to avoid duplicate assets when re-running

After import, create a Media wrapper **only when none exists** for that asset:

```
cms_edit ["list", "--type", "media", "--asset-id", "<newPortraitAssetId>"]
cms_edit ["create", "media", "--asset-id", "<newPortraitAssetId>"]
```

**Media entry `name` (CMS list label):** defaults to the **linked asset title**. Only pass `--name` when you deliberately need a different label (e.g. two Media wrappers on one asset with distinct roles). Never use `visual-{assetId}` or `Wrapper for {assetId}` — those are migration leftovers.

To rename an existing Media wrapper: `cms_edit ["batch", "set", "<media-entry-id>:name=<asset-title>"]` then `batch save`.

Avoid `asset upload --with-media` when multiple entries will share the same image (e.g. news composites) — it creates duplicate Media entries. Upload the asset only, then one shared `create media`, then link the media ID on each entry.

**Prefer pipeline import** for encoded masters. **Video** must use import. `asset upload --url` is only for **pipeline ready images** (or SVG/PDF/Lottie). A random PNG or Contentful CDN master is rejected.

### Local CLI (only when user approves)

Hosted MCP uses `cms_edit_request_staged_upload` then **media prepare** for raster/video (or `asset upload --staged` for SVG/PDF/Lottie). Do not use the local `cms-edit` CLI for uploads.

## Link uploaded asset to an entry

Upload returns an **asset ID**. Attach it, then save:

**Person portrait (`media` is an Asset link):**

```
cms_edit ["open", "--id", "<person-entry-id>"]
cms_edit ["asset", "set", "@root", "media", "<new-asset-id>"]
cms_edit ["diff"]
cms_edit ["save"]
```

**Component `visual` (Media Entry link, singular):**

```
cms_edit ["set", "@cN", "visual", "<media-entry-id>", "--link"]
```

**Article featured image / asset fields:** `asset set <ref> <field> <asset-id>` (or `set … --asset`) when the field is an Asset link.

Always `diff` → `save`. Verify with `preview urls` on the public path.

## Confirmation gates

1. Report search results before uploading
2. Confirm upload filename/title with user if ambiguous
3. After upload, confirm `asset info <id>` shows expected width/height/size before linking

## Out of scope

- Publish assets (draft upload; human publishes in Contentful UI if needed)
- Deleting orphan assets from failed uploads (human cleanup in Contentful)

## Related resources

- `task-media-pipeline-prepare`

- `cms-edit://customer/defaults` (featured image rules)
- `cms-edit://customer/people` (person `media` field, when present)