> For the complete documentation index, see [llms.txt](https://docs.tnid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tnid.com/api-reference/001_user/012_documents/002__prepare_document_upload_as_user.md).

# Prepare Document Upload (User)

GraphQL endpoint: `/user`

Reserves space in the calling user's document repository and returns a presigned POST policy to upload the file with. The reservation holds the declared bytes against the quota but stays invisible until `confirmDocumentUpload` claims it; an upload that never completes is reclaimed by the sweeper.

## Query

```graphql
mutation ($fileName: String!, $contentType: String!, $byteSize: String!) {
  prepareDocumentUpload(fileName: $fileName, contentType: $contentType, byteSize: $byteSize) {
    documentId
    url
    fields
  }
}

```

## Variables

```json
{
  "byteSize": "1024",
  "contentType": "application/pdf",
  "fileName": "invoice.pdf"
}
```

## Response

```json
{
  "data": {
    "prepareDocumentUpload": {
      "documentId": "00000000-0000-4000-8000-000000000001",
      "fields": {
        "Content-Type": "application/pdf",
        "Policy": "eyJjb25kaXRpb25zIjpbeyJYLUFtei1BbGdvcml0aG0iOiJBV1M0LUhNQUMtU0hBMjU2In0seyJYLUFtei1DcmVkZW50aWFsIjoiU09NRV9SQU5ET01fQUNDRVNTX0tFWS8yMDI2MDkwOC91cy1lYXN0LTEvczMvYXdzNF9yZXF1ZXN0In0seyJYLUFtei1EYXRlIjoiMjAyNjA5MDhUMDkwNDUwWiJ9LHsiYnVja2V0IjoidG5pZC12Mi1kb2N1bWVudHMtbG9jYWwifSx7ImtleSI6InVzZXIvZjg4ZDQzYjctMDc5YS00NmJhLWI0YmEtNWNlMzc4ZWE2MDExLzIwMjYtMDktMDhfNFpsWHpNSE1IdnVsX2ludm9pY2UucGRmIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMCwxMDI0XSxbImVxIiwiJENvbnRlbnQtVHlwZSIsImFwcGxpY2F0aW9uL3BkZiJdXSwiZXhwaXJhdGlvbiI6IjIwMjYtMDktMDhUMDk6MDk6NTAuMzQ0NTc1WiJ9",
        "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
        "X-Amz-Credential": "SOME_RANDOM_ACCESS_KEY/20260115/us-east-1/s3/aws4_request",
        "X-Amz-Date": "20260115T090000Z",
        "X-Amz-Signature": "de4bffb7dd8934f292289db9aae0cfc2c6548ef79c72e2b13c3f586cf5ea8338",
        "key": "user/00000000-0000-4000-8000-000000000002/2026-09-08_4ZlXzMHMHvul_invoice.pdf"
      },
      "url": "http://localhost:4566/tnid-v2-documents-local"
    }
  }
}
```
