Content

Media and image uploads

Uploads do not pass through the API. You ask for a presigned URL, you PUT the bytes at object storage, and you tell us it finished. Three requests, and the file never touches our bandwidth or our memory.

Updated 2026年9月23日

3 min read

Endpoints

MethodPathWhat it doesAuth
POST/v1/blog/mediaRecord a file and get an upload URLSession or agent
POST/v1/blog/media/{id}/completeConfirm the upload finishedSession or agent
GET/v1/blog/mediaList mediaKey or session
PATCH/v1/blog/media/{id}Set the alternative textSession or agent
DELETE/v1/blog/media/{id}Delete mediaSession or agent

The three requests

  1. Ask for a URL

    Send the filename, the media type, the size and a SHA-256 of the bytes. You get back a media row with uploadStatus: "pending" and a presigned URL that expires shortly.

    bash
    curl -X POST https://api.cmskite.com/v1/blog/media \
      -H "authorization: Bearer $ACCESS_TOKEN" \
      -H "x-tenant-id: $WORKSPACE_ID" \
      -H "x-project-id: $PROJECT_ID" \
      -H 'content-type: application/json' \
      -d '{
        "filename": "rotterdam.jpg",
        "mimeType": "image/jpeg",
        "sizeBytes": 481223,
        "checksumSha256": "9f86d0818…",
        "width": 1600,
        "height": 900
      }'
  2. PUT the bytes

    Straight at object storage, from wherever the file is — including the visitor’s browser. No credential of yours is involved; the presigned URL is the authorisation, and it is narrow and short-lived.

    bash
    curl -X PUT "$UPLOAD_URL" \
      -H 'content-type: image/jpeg' \
      --data-binary @rotterdam.jpg
  3. Confirm it

    The media row flips to ready and becomes visible to a project key. Until then it is not served: a half-finished upload is not content.

    bash
    curl -X POST https://api.cmskite.com/v1/blog/media/$MEDIA_ID/complete \
      -H "authorization: Bearer $ACCESS_TOKEN" \
      -H "x-tenant-id: $WORKSPACE_ID" \
      -H "x-project-id: $PROJECT_ID"

The same file twice is the same file

Media is content-addressed by its checksum within a project. Re-uploading the same logo for the fortieth time returns the row you already have instead of making a fortieth copy — which is the most common thing a media library is asked to do, and makes uploading idempotent for free.

What makes the image worth having

An image is roughly always the heaviest thing on an article page, and three fields decide whether it helps the page or holds it back. All three are yours to send, because the bytes never pass through us — we cannot open the file to work them out.

  • filename becomes the last part of the stored object’s address, sanitised and made unique. Name it after the post — porto-harbour-at-dawn.webp is what an image search reads; IMG_4821.JPEG is not.
  • width and height are the intrinsic pixel size. Send them and a page can reserve the space before the bytes land; leave them out and the article reflows when the image arrives, which is the layout shift a page is scored on.
  • altText is the sentence read aloud in place of the picture, and the only description of it a search engine can read. Set it with PATCH /v1/blog/media/{id} — usually after the upload, since it is written while looking at the image. An empty value means the image is decorative and should be skipped, which is a real answer, not a missing one.

All three come back on featuredMedia when you read a post, so a page can render <img src alt width height> from one response with no second request.

Shrink before you send. A 6MB photo straight off a phone is 6MB every visitor downloads to fill an 800px slot. Re-encode to WebP and cap the longest edge at about 2048px before uploading — the dashboard does this in the browser, and the checksum you send must be of the bytes you actually store.

What is accepted

  • Images and documents. A text/html upload is refused: a file served from your domain that can run script is not a media library, it is an XSS vector.
  • A malformed checksum or a negative size is a 400 before any URL is issued.
  • Storage is metered per plan. blog.media.storage_bytes is the capability; your dashboard shows what you have used.
  • An upload that is never confirmed is reaped. A presigned URL that nobody used costs you nothing.
  • A picture is removed when the last post using it stops — whether that post was deleted, or its featuredMediaId was changed or cleared. Never while another post still points at it: media is shared by content hash, so one picture can belong to many posts.
Media is a paid capability. The free plan does not include uploads. The request comes back 403 ENTITLEMENT_REQUIRED naming blog.media.enabled, so a client can tell this apart from a bug.