# Upload image attachment

### URL

<mark style="color:green;">**POST**</mark> `https://api.complycube.com/v1/documents/:id/upload/:documentSide`

Associates an image attachment to an existing document.\
\
The images must be either in **JPG**, **PNG**, or **PDF** format. Each side of the document must be between **34 KB** and **4 MB**.

### Headers

<table><thead><tr><th width="265">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>Content-Type</code><mark style="color:red;">*</mark></td><td>string</td><td>The content-type must always be set to <code>application/json</code>.</td></tr><tr><td><code>Authorization</code><mark style="color:red;">*</mark></td><td>string</td><td>The API <strong><code>live</code></strong> or <strong><code>test</code></strong> key.</td></tr></tbody></table>

### Path parameters

<table><thead><tr><th width="265">Name</th><th width="99">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>documentSide</code><mark style="color:red;">*</mark></td><td>string</td><td>The side of document being attached. Valid values include:<br>1. <code>front</code><br>2. <code>back</code></td></tr><tr><td><code>id</code><mark style="color:red;">*</mark></td><td>string</td><td>The ID of the document.</td></tr></tbody></table>

### Body

<table><thead><tr><th width="266">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>fileName</code><mark style="color:red;">*</mark></td><td>string</td><td>The file name. It must end with <code>.jpg</code>, <code>.jpeg</code>, <code>.png</code>, or <code>.pdf</code>.</td></tr><tr><td><code>data</code><mark style="color:red;">*</mark></td><td>string</td><td>The <code>BASE64</code> encoded data.</td></tr></tbody></table>

### Example request

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.complycube.com/v1/documents/{:documentId}/upload/{:documentSide} \
     -H 'Authorization: <YOUR_API_KEY>' \
     -H 'Content-Type: application/json' \
     -d '{
          	"fileName": "front-test.jpg",
          	"data": "<BASE64_DATA_CONTENT>"
        }' 
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { ComplyCube } = require("@complycube/api");

const complycube = new ComplyCube({ apiKey: "<YOUR_API_KEY>" });

await complycube.document.upload("DOCUMENT_ID", {
      fileName: "front-test.jpg",
      data: "<BASE64_DATA_CONTENT>"
}, "DOCUMENT_SIDE");
```

{% endtab %}

{% tab title="Python" %}

```python
from complycube import ComplyCubeClient
cc_api = ComplyCubeClient(api_key='<YOUR_API_KEY>')

doc_front = {
    'fileName': 'passport_front.jpg',
    'data': '<BASE_64_ENCODED>'
}

img = cc_api.documents.upload('DOCUMENT_ID','DOCUMENT_SIDE',**doc_front)
```

{% endtab %}

{% tab title="PHP" %}

```php
use ComplyCube\ComplyCubeClient;

$ccapi = new ComplyCubeClient('<YOUR_API_KEY>');

$img = $ccapi->documents()->upload('DOCUMENT_ID', 'front', [
    'fileName' => 'passport_front.jpg',
    'data' => '<BASE64_CONTENT>'
]);
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using ComplyCube.Net;
using ComplyCube.Net.Resources.Documents;
using ComplyCube.Net.Resources.Images;

var docApi = new DocumentApi(new ComplyCubeClient("<YOUR_API_KEY>"));

var docFront = new ImageRequest {
  fileName = "front-test.jpg",
  data = "<BASE64_CONTENT>"
};

var img = await docApi.UploadImageAsync("DOCUMENT_ID", "front", docFront);
```

{% endtab %}
{% endtabs %}

### Example responses

{% tabs %}
{% tab title="Success (200)" %}

```json
{
    "id": "5eb169302d868c0008828591",
    "fileName": "front-test.jpg",
    "documentSide": "front",
    "downloadLink": "/documents/5eb158880c19580007310f22/images/5eb169302d868c0008828591/download",
    "contentType": "image/jpg",
    "size": 72716,
    "createdAt": "2020-01-04T17:24:29.146Z",
    "updatedAt": "2020-01-04T17:24:29.146Z"
}
```

{% endtab %}

{% tab title="Invalid Request (400)" %}

```json
{
    "type": "invalid_request",
    "message": "Image file size should be between 34KB and 4MB",
    "param": "data"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.complycube.com/documentation/api-reference/core-resources/documents/upload-image-attachment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
