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

# Upload File

> How to upload files to Leavo

## Upload File

```bash theme={null}
POST /backend/uploads
Content-Type: multipart/form-data
```

### Form Parameters

| Field    | Type   | Required | Description                                      |
| -------- | ------ | -------- | ------------------------------------------------ |
| `file`   | file   | Yes      | File to upload (max 10 MB)                       |
| `type`   | string | No       | File type: `media` or `audio` (default: `media`) |
| `folder` | string | No       | Folder to organize the file in storage           |

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.leavo.ai/backend/uploads" \
    -H "Authorization: Bearer your_api_key_here" \
    -F "file=@product_photo.jpg" \
    -F "type=media"
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append('file', fileInput.files[0]);
  formData.append('type', 'media');

  const response = await fetch('https://api.leavo.ai/backend/uploads', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer your_api_key_here'
    },
    body: formData
  });

  const upload = await response.json();
  console.log('File URL:', upload.file_url);
  ```

  ```python Python theme={null}
  import requests

  with open('product_photo.jpg', 'rb') as f:
      response = requests.post(
          'https://api.leavo.ai/backend/uploads',
          headers={'Authorization': 'Bearer your_api_key_here'},
          files={'file': f},
          data={'type': 'media'}
      )

  print('File URL:', response.json()['file_url'])
  ```
</CodeGroup>

### Response (200)

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "tenant_id": "d6b10acc-2307-413f-a4de-4c2edf3f9a70",
  "filename": "product_photo",
  "file_type": "media",
  "file_url": "https://api.leavo.ai/media/proxy/d6b10acc/550e8400.jpg",
  "mime_type": "image/jpeg",
  "size": 1048576,
  "status": "PENDING",
  "created_at": "2024-01-15T10:30:00Z"
}
```

## Send Media in Message

After uploading, use the file to send a media message:

```bash theme={null}
POST /backend/messages/send-media
Content-Type: multipart/form-data
```

| Field          | Type   | Required | Description                              |
| -------------- | ------ | -------- | ---------------------------------------- |
| `channel_id`   | UUID   | Yes      | Channel to send through                  |
| `remote_jid`   | string | Yes      | Recipient (WhatsApp JID)                 |
| `message_type` | string | Yes      | `image`, `audio`, `video`, or `document` |
| `content`      | string | No       | Media caption                            |
| `file`         | file   | Yes      | Media file                               |

### Common Errors

| Code  | Description                         |
| ----- | ----------------------------------- |
| `400` | File not provided or invalid format |
| `413` | File exceeds 10 MB limit            |
