> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/technical-reference/apis-and-mcp/file-upload-and-download-contracts.md).

# File Upload and Download Contracts

File APIs separate uploading bytes from passing a usable file reference to a workflow. Complete every required upload stage before starting the dependent operation.

![Upload a knowledge-base resource](https://1957915746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FgFD8Vge1ezQUfM7klP8A%2Ffile-upload-and-download-contracts.png?alt=media)

This example uses the direct multipart knowledge-base upload contract. A 202 response accepts the upload; inspect indexing status before retrieval. Presigned upload flows have separate allocation and finalization steps.

<details>

<summary>Copy the example</summary>

```bash
curl -X POST \
  "$STACKAI_BASE_URL/v2/knowledge-bases/$KB_ID/resources" \
  -H "Authorization: Bearer $STACKAI_API_KEY" \
  -F "file=@policy.pdf"

# Then inspect the resource returned by the upload.
curl \
  "$STACKAI_BASE_URL/v2/knowledge-bases/$KB_ID/resources/$RESOURCE_ID" \
  -H "Authorization: Bearer $STACKAI_API_KEY"
```

</details>

## Before you begin

The public upload contract and a file within its stated limits.

## Key concepts

| Term           | Definition                                                                                                                                                      |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Upload         | Transfer of file bytes through a supported interface or API. Upload acceptance does not establish parsing or indexing completion.                               |
| Finalization   | A required confirmation step for upload methods that separate allocation from completion. Do not use an allocated upload URL as if the file were already ready. |
| File reference | An identifier or URL used to pass a file to a supported operation. It must be accessible and use the format expected by that operation.                         |
| Signed URL     | A temporary link authorizing access under its issuance conditions. It can expire and may remain usable until expiration after other permissions change.         |
| Request body   | The payload transmitted with an HTTP request. Interpret it using the content type expected by the endpoint.                                                     |

## Upload a file and use its reference

1. Create the upload request with the required file metadata.
2. Upload bytes using the returned method and headers, then finalize if the contract requires it.
3. Use the completed file reference in the workflow input and inspect the resulting file output.

The workflow receives an accessible file in the required input format.

## Behavior and limitations

An allocated upload URL is not a completed file. Use the documented checksum format rather than substituting a hexadecimal digest for base64. Signed URLs can expire and should not serve as permanent identifiers. File size limits differ between upload methods.

## Related resources

[API Versions and Compatibility](https://docs.stackai.com/technical-reference/apis-and-mcp/api-versions-and-compatibility.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/technical-reference/apis-and-mcp/file-upload-and-download-contracts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
