Files

REST endpoints for files. Bearer-auth required.

GET /api/files

List files with pagination.

Query parameters

  • limit (optional): Page size (1–100, default 100).
  • after (optional): Keyset cursor — return the page after this row (next page).
  • before (optional): Keyset cursor — return the page before this row (prev page).
  • ids (optional): Comma-separated list of IDs. Narrows results to these IDs within the caller's accessible scope (does not bypass access checks).
  • filter (optional): Nested filter expression (<Entity>Filter): AND/OR/NOT + per-field comparison operators + relation traversal. JSON-encoded on the query string.
  • orderBy (optional): Multi-key sort (<Entity>OrderBy[]): array of { field: direction } applied in order. Directions: asc/desc plus the four explicit nulls variants. JSON-encoded on the query string.
  • workspace_id (optional): Filter to files in this workspace. When omitted, returns files across every workspace the caller is a member of (admins see all).
  • directory_id (optional): Filter to files inside this directory.
  • mime (optional): Filter by MIME type prefix or exact match.
  • include_deleted (optional): Soft-deleted file visibility. false (default) — active rows only. true — active plus soft-deleted. only — soft-deleted rows only (trash view).
  • name (optional): Case-insensitive substring match on name.
  • status (optional): Shorthand: filter where status equals this value.
  • created_by (optional): Shorthand: filter where createdBy equals this value.

Response

JSON
{
  "data": [
    {
      "id": "<...>",
      "workspaceId": "<...>",
      "directoryId": "<...>",
      "name": "<...>",
      "mime": "<...>",
      "size": "<...>",
      "status": "<...>",
      "errorMessage": "<...>",
      "metadata?": "<...>",
      "createdBy": "<...>",
      "createdAt": "<...>",
      "updatedAt": "<...>",
      "finalizedAt": "<...>",
      "expiresAt": "<...>"
    }
  ],
  "pageInfo": {
    "total": "number",
    "hasNextPage": "boolean",
    "hasPreviousPage": "boolean",
    "startCursor": "string",
    "endCursor": "string"
  }
}

POST /api/files

Initiate file upload

Create a file row in uploading state and return signed PUT URLs for every multipart part. Upload bytes directly to R2 via the parts[].signedUrl entries, then call POST /api/files/{id}/complete with the collected ETags.

Request body

JSON
{
  "workspaceId": "string",
  "directoryId?": "string",
  "name": "string",
  "size": "integer",
  "declaredContentType": "string",
  "partSize?": "integer"
}

Response

JSON
{
  "file": "any",
  "parts": ["<...>"]
}

GET /api/files/{id}

Get a file by ID.

Path parameters

  • id (required): File to retrieve.

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

PATCH /api/files/{id}

Rename or move file

Path parameters

  • id (required):

Request body

JSON
{
  "name?": "string",
  "directoryId?": "string",
  "expiresAt?": "string"
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

DELETE /api/files/{id}

Soft-delete a file.

Path parameters

  • id (required): File to soft-delete.

Response

JSON
{
  "success": "boolean"
}

POST /api/files/{id}/abort

Abort file upload

Abort an in-progress multipart upload. The file row flips to error and the R2 multipart upload is released.

Path parameters

  • id (required):

Response

JSON
{
  "success": "boolean"
}

POST /api/files/{id}/complete

Complete file upload

Finalize the multipart upload with the ordered list of part ETags. The service flips the file to ready, sniffs the real mime type, and (for image/_ and video/_) emits a provision event to create the CF Images / CF Stream side row asynchronously.

Path parameters

  • id (required): The file's prefixed ID (e.g. fil_...).

Request body

JSON
{
  "parts": [
    {
      "partNumber": "<...>",
      "etag": "<...>",
      "size?": "<...>"
    }
  ]
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/{id}/parts

Sign additional upload parts

Return signed PUT URLs for the given part numbers. Used by progressive upload clients that sign parts on demand.

Path parameters

  • id (required): The file's prefixed ID (e.g. fil_...).

Request body

JSON
{
  "partNumbers": ["integer"]
}

Response

JSON
{
  "parts": ["<...>"]
}

DELETE /api/files/{id}/purge

Permanently delete a soft-deleted file.

Path parameters

  • id (required): Soft-deleted file to permanently delete.

Response

JSON
{
  "success": "boolean"
}

POST /api/files/{id}/restore

Restore a soft-deleted file.

Path parameters

  • id (required): Soft-deleted file to restore.

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/{id}/to-markdown

Convert a file to markdown

Convert an existing file (PDF / DOCX / PPTX / XLSX / image / HTML / plain text) to markdown via Cloudflare Workers AI. Stored as a new text/markdown file. Temp-by-default (1 day TTL at workspace root) unless a directoryId is provided.

Path parameters

  • id (required): The file's prefixed ID (e.g. fil_...).

Request body

JSON
{
  "directoryId?": "string",
  "name?": "string",
  "ttlMs?": "integer"
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/html-from-url

Fetch rendered HTML of a URL

Fetch a URL via Cloudflare Browser Rendering and capture the post-render HTML. Stored as a text/html file. Temp-by-default (1 day TTL at workspace root) unless a directoryId is provided.

Request body

JSON
{
  "workspaceId": "string",
  "url": "string",
  "directoryId?": "string",
  "name?": "string",
  "ttlMs?": "integer",
  "browser?": {
    "viewport?": "<...>",
    "waitForSelector?": "<...>",
    "waitForTimeout?": "<...>",
    "userAgent?": "<...>",
    "authenticate?": "<...>",
    "cookies?": "<...>",
    "extraHeaders?": "<...>",
    "gotoOptions?": "<...>",
    "bestAttempt?": "<...>",
    "allowRequestPattern?": "<...>",
    "rejectRequestPattern?": "<...>",
    "allowResourceTypes?": "<...>",
    "rejectResourceTypes?": "<...>",
    "setJavaScriptEnabled?": "<...>"
  }
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/markdown-from-url

Render a URL to markdown

Fetch a URL via Cloudflare Browser Rendering and extract its content as markdown. Stored as a text/markdown file. Temp-by-default (1 day TTL at workspace root) unless a directoryId is provided.

Request body

JSON
{
  "workspaceId": "string",
  "url": "string",
  "directoryId?": "string",
  "name?": "string",
  "ttlMs?": "integer",
  "browser?": {
    "viewport?": "<...>",
    "waitForSelector?": "<...>",
    "waitForTimeout?": "<...>",
    "userAgent?": "<...>",
    "authenticate?": "<...>",
    "cookies?": "<...>",
    "extraHeaders?": "<...>",
    "gotoOptions?": "<...>",
    "bestAttempt?": "<...>",
    "allowRequestPattern?": "<...>",
    "rejectRequestPattern?": "<...>",
    "allowResourceTypes?": "<...>",
    "rejectResourceTypes?": "<...>",
    "setJavaScriptEnabled?": "<...>"
  }
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/pdf-from-url

Render a URL to PDF

Fetch a URL via Cloudflare Browser Rendering, render it to PDF, and store the result as a file row. Temp-by-default (1 day TTL at workspace root) unless a directoryId is provided.

Request body

JSON
{
  "workspaceId": "string",
  "url": "string",
  "directoryId?": "string",
  "name?": "string",
  "ttlMs?": "integer",
  "browser?": {
    "viewport?": "<...>",
    "waitForSelector?": "<...>",
    "waitForTimeout?": "<...>",
    "userAgent?": "<...>",
    "authenticate?": "<...>",
    "cookies?": "<...>",
    "extraHeaders?": "<...>",
    "gotoOptions?": "<...>",
    "bestAttempt?": "<...>",
    "allowRequestPattern?": "<...>",
    "rejectRequestPattern?": "<...>",
    "allowResourceTypes?": "<...>",
    "rejectResourceTypes?": "<...>",
    "setJavaScriptEnabled?": "<...>"
  },
  "pdf?": {
    "format?": "<...>",
    "landscape?": "<...>",
    "scale?": "<...>",
    "printBackground?": "<...>",
    "displayHeaderFooter?": "<...>",
    "headerTemplate?": "<...>",
    "footerTemplate?": "<...>",
    "margin?": "<...>",
    "width?": "<...>",
    "height?": "<...>",
    "preferCSSPageSize?": "<...>"
  }
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}

POST /api/files/screenshot-from-url

Screenshot a URL

Fetch a URL via Cloudflare Browser Rendering, capture a screenshot (png/jpeg/webp), and store the result as a file row. The file is NOT auto-provisioned as a CF Images entity — callers that want variants can create an image from a permanent copy.

Request body

JSON
{
  "workspaceId": "string",
  "url": "string",
  "directoryId?": "string",
  "name?": "string",
  "ttlMs?": "integer",
  "browser?": {
    "viewport?": "<...>",
    "waitForSelector?": "<...>",
    "waitForTimeout?": "<...>",
    "userAgent?": "<...>",
    "authenticate?": "<...>",
    "cookies?": "<...>",
    "extraHeaders?": "<...>",
    "gotoOptions?": "<...>",
    "bestAttempt?": "<...>",
    "allowRequestPattern?": "<...>",
    "rejectRequestPattern?": "<...>",
    "allowResourceTypes?": "<...>",
    "rejectResourceTypes?": "<...>",
    "setJavaScriptEnabled?": "<...>"
  },
  "screenshot?": {
    "type?": "<...>",
    "quality?": "<...>",
    "fullPage?": "<...>",
    "omitBackground?": "<...>",
    "selector?": "<...>",
    "captureBeyondViewport?": "<...>"
  }
}

Response

JSON
{
  "id": "string",
  "workspaceId": "string",
  "directoryId": "string",
  "name": "string",
  "mime": "string",
  "size": "number",
  "status": "uploading | ready | error",
  "errorMessage": "string",
  "metadata?": "any",
  "createdBy": "string",
  "createdAt": "string",
  "updatedAt": "string",
  "finalizedAt": "string",
  "expiresAt": "string"
}