> ## Documentation Index
> Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Attachment

> Upload a file and get back base64 attachment data ready to use in a campaign

Accepts a `multipart/form-data` upload and returns the file encoded as base64. Pass the returned `attachment` object directly into the `attachments` array of [Send Campaign](/docs/api-reference/campaigns/send).

**Limits**

* Max file size: **10 MB** per file
* Allowed types: PDF, Word, Excel, plain text, CSV, JPEG, PNG, GIF, WebP

## Headers

<ParamField header="Authorization" type="string" required>
  `Bearer YOUR_API_KEY`
</ParamField>

<ParamField header="X-Project-ID" type="string">
  Your project UUID. Not required if the API key already encodes the project.
</ParamField>

## Request Body

<ParamField body="file" type="file" required>
  The file to upload (`multipart/form-data`)
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  `true` on successful upload
</ResponseField>

<ResponseField name="attachment" type="object">
  Ready-to-use attachment object

  <Expandable title="Attachment fields">
    <ResponseField name="content" type="string">
      Base64-encoded file content
    </ResponseField>

    <ResponseField name="filename" type="string">
      Original filename
    </ResponseField>

    <ResponseField name="type" type="string">
      MIME type
    </ResponseField>

    <ResponseField name="size" type="number">
      File size in bytes
    </ResponseField>

    <ResponseField name="disposition" type="string">
      Always `"attachment"`
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable confirmation
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.usegately.com/api/v1/campaigns/upload-attachment" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "X-Project-ID: YOUR_PROJECT_ID" \
    -F "file=@/path/to/report.pdf"
  ```

  ```typescript SDK (browser only) theme={null}
  import { GatelyCampaigns } from '@gately/sdk'

  const campaigns = new GatelyCampaigns({ projectId: 'YOUR_PROJECT_ID' })

  const fileInput = document.querySelector<HTMLInputElement>('#file-input')
  const file = fileInput!.files![0]

  const { attachment } = await campaigns.uploadAttachment(file)

  // Pass directly into send()
  await campaigns.send({
    name: 'Monthly Report',
    subject: 'Your report is attached',
    content: '<p>Please find your report attached.</p>',
    recipient_emails: ['user@example.com'],
    attachments: [attachment],
  })
  ```
</RequestExample>

<ResponseExample>
  ```json Success theme={null}
  {
    "success": true,
    "attachment": {
      "content": "JVBERi0xLjQKJcOkw7zDtsO...",
      "filename": "report.pdf",
      "type": "application/pdf",
      "size": 204800,
      "disposition": "attachment"
    },
    "message": "File uploaded successfully"
  }
  ```

  ```json File too large theme={null}
  {
    "error": "File size exceeds 10 MB limit"
  }
  ```

  ```json Unsupported type theme={null}
  {
    "error": "File type application/zip is not allowed"
  }
  ```
</ResponseExample>
