---
title: "Replace file"
method: PUT
path: "/api/files/{ns}/{id}"
tags: ["Files"]
---

# Replace file

`PUT /api/files/{ns}/{id}`

## Request

- Base URL: `https://brewpage.app`
- URL: `https://brewpage.app/api/files/{ns}/{id}`
- Auth: one of:
  - API key in header `X-Owner-Token`
  - API key in header `X-Manage-Key`

Replaces the file content (multipart 'file'); same type rules and limits as upload. Keeps link, password, TTL and tags. For an HTML or Markdown file published as a page, replaces that page (same rules as PUT /api/html). HTML or Markdown over an existing file makes it a page at the same address, keeping owner, password, TTL, tags and views.

## Path parameters

- `ns` string, required
- `id` string, required

## Query parameters

- `ttl` string
- `format` string

## Headers

- `X-Owner-Token` unknown
- `X-Manage-Key` unknown

## Request body `multipart/form-data`

- object
  - `file` string, binary: File part; any single file part is accepted when 'file' is absent

## Response `200`

File replaced

- FileUpdateResponse: Replace result. For a file published as a page (notice 'html-file-as-page', 'markdown-file-as-page' or 'file-format-applied') the page was replaced
  - `id` string, required
  - `namespace` string, required
  - `filename` string, required: Stored name of the new content
  - `contentType` string: Detected MIME type of the new content
  - `sizeBytes` integer, required
  - `link` string, required
  - `ownerLink` string, required
  - `expiresAt` string, date-time, required: Unchanged: updates keep the original expiry
  - `listed` boolean, required: true = listed in the gallery and sitemap now (public, no password, not hidden).
  - `listable` boolean, required: false = never listed in the gallery whatever the namespace (JSON and KV, JSON pages, HTML and JSON files); listing does not apply
  - `notices` PublishNotice[]: Advisories about the request or its result; omitted when none.
    - `code` string, required: Kebab-case, e.g. ttl-clamped, namespace-defaulted, secret-detected, visibility-not-listable, extend-needs-profile, rotate-still-listed, private-domain-detached, badge-hide-needs-profile, owner-token-new (save the new ownerToken, reuse it), credential-published (token or manage link in public content: remove it, reset it), archive-unverified (archive: check contents before opening).
    - `message` string, required

## Other responses

- `400`: Invalid request or file too large; or PDF/Office file unreadable or password-protected
- `403`: Missing or wrong owner token or management key, or upload refused
- `404`: File not found or expired; body has createUrl: POST the content there to publish anew
- `409`: Old publication is read-only (code: OLD_PUBLICATION_READ_ONLY; publish anew via createUrl), or the same content is another file of this owner
- `422`: Unsupported file type or content of no supported type
- `429`: Rate limited: wait Retry-After (= retryAfterSeconds); no account: accountUrl, free sign-up with higher limits
- `503`: Busy; retry after Retry-After seconds

## Changes

- **2026-11-21** `19a6c5561e70`: 7 info
  - added the optional property `level` to the response with the `400` status
  - added the optional property `level` to the response with the `403` status
  - added the optional property `level` to the response with the `404` status
  - added the optional property `level` to the response with the `409` status
  - …3 more
- **2026-11-12** `fb6013b0284a`: 1 info
  - added the required property `listable` to the response with the `200` status
- **2026-11-11** `957711dab4b5`: 14 info
  - added the optional property `challengeUrl` to the response with the `400` status
  - added the optional property `challengeUrl` to the response with the `403` status
  - added the optional property `challengeUrl` to the response with the `404` status
  - added the optional property `challengeUrl` to the response with the `409` status
  - …10 more
- **2026-11-10** `e34e8877bb89`: 14 info
  - added the optional property `reason` to the response with the `400` status
  - added the optional property `reason` to the response with the `403` status
  - added the optional property `reason` to the response with the `404` status
  - added the optional property `reason` to the response with the `409` status
  - …10 more
- **2026-11-05** `f7c94aab1869`: 1 info
  - added the new optional `query` request parameter `format`

[Operation history](https://skmtc.dev/brewpage/apis/brewpage-api/changes/api/files/:ns/:id/put.md)

---

[API](https://skmtc.dev/brewpage/apis/brewpage-api.md) - [All operations](https://skmtc.dev/brewpage/apis/brewpage-api/llms.txt) - [OpenAPI document](https://skmtc.dev/brewpage/apis/brewpage-api/revisions/78d2720a18a9?raw)
