# Files and attachments (API)

> How to upload a file through the Sofia Space API in three steps and attach it to a task or a docs page, plus listing a task's or page's attachments.

Source: https://docs.sofiaspace.uz/api/files-and-attachments/

Files reach Sofia Space in three steps: you **ask for an upload**, **send the bytes** straight to storage on the address you get back, then **confirm**. The confirmed file can then be **attached** to a task or a docs page — for example a signed contract PDF from your CRM, or a monthly report from your ERP.

**Scope:** uploading needs `tasks:write` or `docs:write`; attaching to a task needs `tasks:write`, to a page `docs:write`; listing needs `tasks:read` or `docs:read`. You must be able to edit the task or page. Tokens with only the script scopes (`task:create`, `doc:create`) can't upload.

**Size limit per file:** the smaller of your plan's largest-file limit and 100 MB. On Free that is 25 MB; on paid plans, 100 MB. Every upload also counts toward the workspace's storage. See [Limits](https://docs.sofiaspace.uz/reference/limits.md).

## Upload and attach a file: the whole flow

Example: attach `contract-1042.pdf` (248,113 bytes) to task `SALES-42`.

1. **Compute the file's SHA-256** (64 hex characters):

   ```bash
   shasum -a 256 contract-1042.pdf
   # 28eb2bd698097d10caa10931fa26e05b2afa5e2c2fdec83df7d292659dfec556  contract-1042.pdf
   ```

2. **Ask for an upload.** `module` is `task` for a task attachment or `doc` for a page attachment. Send it: without it the 25 MB chat limit applies:

   ```bash
   curl -X POST https://acme.sofiaspace.uz/api/v1/files/upload-requests \
     -H "Authorization: Bearer $SOFIA_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "orgId": "6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20",
       "fileName": "contract-1042.pdf",
       "mimeType": "application/pdf",
       "sizeBytes": 248113,
       "checksum": "28eb2bd698097d10caa10931fa26e05b2afa5e2c2fdec83df7d292659dfec556",
       "module": "task"
     }'
   ```

   ```json
   {
     "fileId": "d4f6a8c1-3e5b-4d7f-9a1c-2e4f6b8d0a13",
     "alreadyExists": false,
     "uploadUrl": "https://files.sofiaspace.uz/...signed-address...",
     "expiresInSeconds": 900
   }
   ```

   If `alreadyExists` is `true`, **you** already uploaded a file with the same SHA-256 to this workspace: `uploadUrl` is empty, so skip steps 3 and 4 and attach `fileId` (step 5). This happens only for your own earlier uploads (with a token, the token owner's). A file someone else uploaded is never reused, even with identical bytes: you get a new `fileId` and an `uploadUrl`.

3. **Send the bytes** to `uploadUrl` with a `PUT`, with the same `Content-Type` you declared and **no** `Authorization` header:

   ```bash
   curl -X PUT -H "Content-Type: application/pdf" \
     --upload-file contract-1042.pdf "$UPLOAD_URL"
   ```

   Do it before the address expires (`expiresInSeconds`).

4. **Confirm the upload:**

   ```bash
   curl -X POST https://acme.sofiaspace.uz/api/v1/files/d4f6a8c1-3e5b-4d7f-9a1c-2e4f6b8d0a13/confirm \
     -H "Authorization: Bearer $SOFIA_TOKEN"
   ```

   ```json
   {
     "id": "d4f6a8c1-3e5b-4d7f-9a1c-2e4f6b8d0a13",
     "orgId": "6b1f0c3e-2a4d-4c55-9a51-0d3f6a1e7b20",
     "uploadedBy": "2c9a7f41-5b3e-4d1a-8f20-7e6b5c4d3a21",
     "fileName": "contract-1042.pdf",
     "mimeType": "application/pdf",
     "sizeBytes": 248113,
     "checksum": "28eb2bd698097d10caa10931fa26e05b2afa5e2c2fdec83df7d292659dfec556",
     "status": "ACTIVE",
     "createdAt": "2026-11-14T08:00:00Z",
     "confirmedAt": "2026-11-14T08:00:03Z"
   }
   ```

   Confirming checks that the bytes arrived, that their size is exactly `sizeBytes`, that their content is the kind of file `mimeType` says (an image declared as `image/png` must really be an image), and that their SHA-256 is the `checksum` you declared. If not, you get `409` and the uploaded bytes are thrown away; the file stays unconfirmed. Upload the right bytes again to the same `uploadUrl` while it is valid and confirm again, or start again from step 2.

   This is also when the file counts toward the workspace's storage: a workspace that is full gets `409 ENTITLEMENT_DENIED`.

5. **Attach it** to the task (or the page, below):

   ```bash
   curl -X POST https://acme.sofiaspace.uz/api/v1/tasks/7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20/attachments \
     -H "Authorization: Bearer $SOFIA_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"fileId":"d4f6a8c1-3e5b-4d7f-9a1c-2e4f6b8d0a13"}'
   ```

   ```json
   {
     "id": "e5a7b9c2-4f6d-4e8a-8b2d-3f5a7c9e1b24",
     "taskId": "7c3e9a15-2d4f-4b6a-9e8c-1f3a5b7d9e20",
     "fileId": "d4f6a8c1-3e5b-4d7f-9a1c-2e4f6b8d0a13",
     "filename": "contract-1042.pdf",
     "contentType": "application/pdf",
     "sizeBytes": 248113,
     "uploadedBy": "2c9a7f41-5b3e-4d1a-8f20-7e6b5c4d3a21",
     "uploadedAt": "2026-11-14T08:00:04Z"
   }
   ```

   The file now shows under the task's attachments in the app.

## Ask for an upload

`POST /api/v1/files/upload-requests` — **Scope:** `tasks:write` or `docs:write`.

| Field | Type | Required | Meaning |
| --- | --- | --- | --- |
| `orgId` | string | yes | Your organization ID |
| `fileName` | string | yes | Name shown in Sofia Space, with its extension |
| `mimeType` | string | yes | For example `application/pdf`, `image/png` |
| `sizeBytes` | integer | yes | Exact size in bytes, more than 0 |
| `checksum` | string | yes | SHA-256 of the bytes, exactly 64 hex characters (upper or lower case; stored lower-case). It is checked against the bytes when you confirm |
| `module` | string | send it | `task` or `doc`. **Leaving it out applies the chat limit of 25 MB** |

Limits:

- **Size:** 100 MB for `task` and `doc`, and never more than your plan's largest file (25 MB on Free, 250 MB on Pro, 500 MB on Business). In practice: 25 MB on Free, 100 MB on paid plans.
- **Type:** `.exe`, `.dll`, `.bat`, `.cmd`, `.com`, `.scr`, `.msi`, `.jar`, `.app`, `.deb` and `.rpm` files are refused.
- **Rate:** at most 120 upload requests a minute per person; more gets `429` with `Retry-After`.
- The upload address works for 15 minutes (`expiresInSeconds`: `900`).

Errors:

| Status | `code` or `error` | When |
| --- | --- | --- |
| `400` | `INVALID_ARGUMENT` | Over 100 MB for the module ("File exceeds the maximum upload size …"), a refused extension, a missing field, or a `checksum` that isn't 64 hex characters ("checksum must be the file's SHA-256 as 64 hex characters") |
| `403` | `NOT_ORG_MEMBER` | `orgId` is not your token's workspace |
| `409` | `ENTITLEMENT_DENIED` (`key`: `file.max.mb`) | Over your plan's largest file |
| `429` | `RATE_LIMITED` | Over 120 upload requests a minute |

## Confirm an upload

`POST /api/v1/files/{fileId}/confirm` — **Scope:** `tasks:write` or `docs:write`. No body. Safe to repeat: confirming a file that is already confirmed returns it unchanged. Returns the file; `checksum` is only shown to the person who uploaded it.

Errors: `409 FAILED_PRECONDITION` when the bytes never arrived, the size differs from `sizeBytes`, the content isn't the declared type, or its SHA-256 isn't the declared `checksum` ("Uploaded content does not match the declared SHA-256 checksum for file …"). The bytes are deleted and the file stays unconfirmed: upload the right bytes and confirm again. `409 ENTITLEMENT_DENIED` (`key`: `storage.total.gb`) when the workspace's storage is full.

## Task attachments

`GET /api/v1/tasks/{taskId}/attachments` — **Scope:** `tasks:read`. Returns `{"attachments": [ … ]}` with the attachment shape shown above.

`POST /api/v1/tasks/{taskId}/attachments` — **Scope:** `tasks:write`. Body `{"fileId": "…"}`. Returns `200` and the attachment. The name, type and size come from the confirmed file, not from your request. The file must be confirmed and belong to the same workspace.

## Page attachments

`GET /api/v1/pages/{pageId}/attachments` — **Scope:** `docs:read`. Returns `{"attachments": [ … ]}` in the same shape, with `pageId` instead of `taskId`.

`POST /api/v1/pages/{pageId}/attachments` — **Scope:** `docs:write`. Body `{"fileId": "…"}`. Returns `200` and the attachment. Upload with `"module": "doc"`.

## What you can't do with the API

- You can't **download** a file with a token: lists show names, types and sizes, but not download links. The `…/attachments/{fileId}/download-url` routes refuse tokens with `403` and `"error": "SIGNED_IN_APP_ONLY"`. Download in the app.
- You can't **remove** an attachment with a token: `DELETE /api/v1/tasks/{taskId}/attachments/{attachmentId}` and `DELETE /api/v1/pages/{pageId}/attachments/{attachmentId}` refuse tokens with `403` and `"error": "SIGNED_IN_APP_ONLY"`. Remove it in the app. (AI apps signed in through the [Sofia Space MCP server](https://docs.sofiaspace.uz/integrations/mcp-tools.md) can.)
- You can't put files into Drive, chat or a user's avatar with a token, or reuse a file someone else uploaded without uploading it yourself.
- Files over 100 MB can't be uploaded through the API, on any plan.

## Related

- [Description and attachments](https://docs.sofiaspace.uz/tasks/description-and-attachments.md) — files on tasks in the app
- [Images and attachments](https://docs.sofiaspace.uz/docs/images-and-attachments.md) — files on pages
- [Rate limits and size limits](https://docs.sofiaspace.uz/api/rate-limits.md)
