[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Ffiles\u002Fversion-upload":3,"docs-tabs-entities\u002Ffiles\u002Fversion-upload":6},{"content":4,"lastmod":5},"## Upload a new file version\n\n`POST \u002Fv1\u002Ffiles\u002F:id\u002Fversions`\n\nReplaces the content of a file on Bitrix24 Drive and saves it in the version history. The new content is passed as Base64 in the JSON request body, and the file name does not change.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|----------|\n| `id` (path) | number | yes | File ID. Get it: `GET \u002Fv1\u002Ffiles?folderId=X` |\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `content` | string | yes | New file content in Base64: the standard alphabet, `=` padding at the end, no spaces or line breaks. An empty string is not accepted. The whole request body is limited to 70 MiB: Base64 inflates data by a third, so one request fits a file of about 50 MiB |\n| `expectedContentGeneration` | number | no | Expected value of the file's `globalContentVersion`, a non-negative integer. If the file has a different value, the upload does not run and `409 DISK_VERSION_CONFLICT` is returned. Current value: [`GET \u002Fv1\u002Ffiles\u002F:id`](.\u002Fget.md) |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ffiles\u002F205\u002Fversions\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"content\":\"UmVwb3J0IHYy\",\"expectedContentGeneration\":3}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ffiles\u002F205\u002Fversions\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"content\":\"UmVwb3J0IHYy\",\"expectedContentGeneration\":3}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst content = btoa('Report v2')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ffiles\u002F205\u002Fversions', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ content, expectedContentGeneration: 3 }),\n})\n\nconst { data, meta } = await res.json()\nif (meta.joinedIntoPreviousVersion) {\n  console.log('The latest version was overwritten; the history did not grow')\n}\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst content = btoa('Report v2')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ffiles\u002F205\u002Fversions', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ content, expectedContentGeneration: 3 }),\n})\n\nconst { data, meta } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `success` | boolean | Always `true` on success |\n| `data` | object | The file after the upload — the same fields as in the [`GET \u002Fv1\u002Ffiles\u002F:id`](.\u002Fget.md) response |\n| `data.globalContentVersion` | number | File version counter. Grows by one after the upload |\n| `data.size` | number | Size of the new content in bytes |\n| `meta.joinedIntoPreviousVersion` | boolean\\|null | `true` — the upload overwrote the latest version, and the history did not grow. `false` — a new version appeared in the history. `null` — the file history could not be read, so no comparison was made |\n| `meta.inTrash` | boolean | `true` — the file is in the trash, and its content was replaced anyway |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"id\": 205,\n    \"name\": \"report.txt\",\n    \"code\": null,\n    \"storageId\": 1,\n    \"type\": \"file\",\n    \"folderId\": 27,\n    \"deletedType\": 0,\n    \"globalContentVersion\": 4,\n    \"fileId\": 369,\n    \"size\": 9,\n    \"createdAt\": \"2026-10-15T17:09:58.000Z\",\n    \"updatedAt\": \"2026-10-15T17:09:59.000Z\",\n    \"deletedAt\": null,\n    \"createdBy\": 1,\n    \"updatedBy\": 1,\n    \"deletedBy\": null,\n    \"downloadUrl\": \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Ffiles\u002F205\u002Fdownload\",\n    \"detailUrl\": \"https:\u002F\u002Fexample.bitrix24.com\u002Fcompany\u002Fpersonal\u002Fuser\u002F1\u002Fdisk\u002Ffile\u002Freport.txt\"\n  },\n  \"meta\": {\n    \"joinedIntoPreviousVersion\": true,\n    \"inTrash\": false\n  }\n}\n```\n\n## Error response example\n\n409 — `expectedContentGeneration` did not match the file's `globalContentVersion`:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"DISK_VERSION_CONFLICT\",\n    \"message\": \"The content generation changed. Read the file before uploading.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 409 | `DISK_VERSION_CONFLICT` | `expectedContentGeneration` did not match the file's `globalContentVersion`. The content is not changed |\n| 400 | `INVALID_PARAMS` | `content` is empty or not in standard Base64 |\n| 400 | `INVALID_PARAMS` | `expectedContentGeneration` is not a non-negative integer |\n| 400 | `INVALID_ID` | `id` is not a positive integer |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |\n| 401 | `TOKEN_MISSING` | Access tokens for the Bitrix24 portal are unavailable |\n| 403 | `SCOPE_DENIED` | The key lacks the `disk` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. The address of the page where the mode is changed is in `error.details.switchUrl` |\n| 404 | `ENTITY_NOT_FOUND` | There is no file with this `id`, or it is not available to the key |\n| 413 | `PAYLOAD_TOO_LARGE` | The request body is larger than 70 MiB |\n| 422 | `DISK_FILE_NOT_SAVED` | Bitrix24 refused the write without an error code — the refusal text is in `error.message` |\n| 422 | `DISK_FILE_NOT_SAVED` | Bitrix24 did not confirm the upload. Read the file before retrying |\n| 429 | `LARGE_BODY_BACKEND_BUSY` | The platform is processing other large requests. Retry after `error.retryAfter` seconds |\n| 502 | `DISK_OUTCOME_UNKNOWN` | The outcome of the write is unknown, and the platform did not retry the request. Before retrying, read the file with [`GET \u002Fv1\u002Ffiles\u002F:id`](.\u002Fget.md) and compare `globalContentVersion` with the previous value: if it grew, the upload went through |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n- **An upload within five minutes of a file change overwrites the latest version.** If the same user changed the file less than five minutes ago, counting from `updatedAt`, the new content replaces the latest version instead of adding a new one. The previous content of that version disappears from the history, and `meta.joinedIntoPreviousVersion` is `true`. Any change to the file by this user starts the countdown, including creation and renaming. To keep the current content as a separate version, upload the new content when at least five minutes have passed since the file's `updatedAt`.\n- **`expectedContentGeneration` is checked before the write, not during it.** The platform reads the file, compares the value, and only then uploads the content. This check does not detect a write by another client between the comparison and the upload.\n- **The file name does not change.** The content is saved under the file's current name, with the same extension. To rename the file, use [`PATCH \u002Fv1\u002Ffiles\u002F:id`](.\u002Fupdate.md).\n\n## See also\n\n- [File version history](\u002Fdocs\u002Fentities\u002Ffiles\u002Fversions)\n- [Restore content from a version](\u002Fdocs\u002Fentities\u002Ffiles\u002Fversion-restore)\n- [Upload file](\u002Fdocs\u002Fentities\u002Ffiles\u002Fupload)\n- [Get file](\u002Fdocs\u002Fentities\u002Ffiles\u002Fget)\n","2026-10-15",{},1795415250354]