<span id="下载工作区原始文件"></span>

# Download a raw workspace file

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Download original file bytes, optionally enforcing a full-file size limit or reading a prefix.

```text
GET https://api.moi.matrixorigin.cn/v5/workspaces/{id}/files/{file_id}/download
```

<span id="调用前准备"></span>

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`; use the corresponding product API URL for a dedicated deployment.

Prepare a personal access token for the target workspace. WORKSPACE_ID must match the path workspace; FILE_ID comes from actual file results. BASE_URL includes the product prefix in the same environment. Example files/IDs are placeholders.

<span id="请求参数"></span>

## Request parameters

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --fail-with-body -sS -X GET "$BASE_URL/workspaces/$WORKSPACE_ID/files/$FILE_ID/download" \
  -H "X-API-Key: $MOI_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -o "$OUTPUT_FILE"
```

Set MAX_BYTES to positive integer bytes, then choose either a full-file limit or prefix read.

```bash
curl --fail-with-body -sS "$BASE_URL/workspaces/$WORKSPACE_ID/files/$FILE_ID/download" \
  -H "X-API-Key: $MOI_KEY" -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "X-MOI-Max-Download-Bytes: $MAX_BYTES" \
  -o "$OUTPUT_FILE"
```

```bash
curl --fail-with-body -sS "$BASE_URL/workspaces/$WORKSPACE_ID/files/$FILE_ID/download" \
  -H "X-API-Key: $MOI_KEY" -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "X-MOI-Download-Prefix-Bytes: $MAX_BYTES" \
  -o "$OUTPUT_FILE"
```

:::::
:::::{tab-item} Parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `X-MOI-Max-Download-Bytes` | integer | No | Positive integer header. Rejects oversized files before reading. |
| `X-MOI-Download-Prefix-Bytes` | integer | No | Positive integer header. Returns at most this many prefix bytes. |

The two headers are mutually exclusive. Content-Length counts bytes in this response; a prefix is not the complete file. zip uses application/zip, other files application/octet-stream. Attachment filenames encode the original name.

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```text
sample
```

:::::
:::::{tab-item} Fields

The response is a byte stream. Consume and close it, and check read/exit status before using the file. Failure after the response starts may interrupt the connection.

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error responses

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 2,
  "message": "示例错误信息"
}
```

:::::
:::::{tab-item} Fields

Invalid byte limits or conflicting limits return 400/2 with details.reason. Errors use numeric code/message. Oversize returns 413/14 with reason=DOWNLOAD_LIMIT_EXCEEDED, file_size, and limit. Missing/denied/unavailable external sources return 404/3, 403/5, and 503/15, with reasons SOURCE_OBJECT_NOT_FOUND, SOURCE_OBJECT_ACCESS_DENIED, and SOURCE_OBJECT_UNAVAILABLE, plus domain/file_id.

:::::
::::::
:::::::
