# Upload a file

**Publié le** : 2026-05-08
**Catégorie** : Media & Files

## `POST /media/upload`

**Upload a file**

Uploads a file via `multipart/form-data`. Supported file types include
images (jpg, png, gif, webp, svg, avif), documents (pdf), and more.

Required permissions: `media.upload`

### Request Body

Content-Type: `multipart/form-data`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | string | Yes | Required |
| `alt` | string | No |  |
| `optimize` | boolean | No | Boolean |
| `preset` | "fast" \| "optimized" \| "quality" | No | One of: fast, optimized, quality |
| `maxWidth` | number | No | Between 100 and 4000 |
| `quality` | number | No | Between 50 and 100 |
| `folderId` | string | No | Media folder UUID |


### Responses

| Status | Description |
| --- | --- |
| `201` | Successful response |
| `401` | Unauthorized — invalid or missing API token |
| `403` | Forbidden — insufficient permissions |
| `422` | Validation error |


> **Notes:** - Maximum file size: 50 MB.
> 
> - Images are automatically processed to generate CDN variants.
> - Set `folderId` to organize the file into a folder.

### Examples

```bash
curl -X POST https://api.lynkow.com/v1/media/upload \
  -H "Authorization: Bearer $API_TOKEN" \
  -F "file=@photo.jpg" \
  -F "alt=A beautiful sunset" \
  -F "folderId=uuid-of-folder"
```

### Response Example

```json
{
  "data": {
    "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "filename": "photo.jpg",
    "originalName": "photo.jpg",
    "mimeType": "image/jpeg",
    "size": 185320,
    "width": 1600,
    "height": 900,
    "alt": "A beautiful sunset",
    "url": "https://cdn.lynkow.com/sites/abc123/photo.jpg",
    "variants": {
      "thumbnail": "https://cdn.lynkow.com/sites/abc123/photo.jpg?w=150",
      "card": "https://cdn.lynkow.com/sites/abc123/photo.jpg?w=400",
      "content": "https://cdn.lynkow.com/sites/abc123/photo.jpg?w=800",
      "medium": "https://cdn.lynkow.com/sites/abc123/photo.jpg?w=1200"
    },
    "folderId": "uuid-of-folder",
    "createdAt": "2025-04-06T11:30:00.000Z"
  }
}
```

---