# Replace a file

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

## `POST /media/:id/replace`

**Replace a file**

Replaces the file data while keeping the same ID and URL. Useful for
updating an image without changing all references.

Required permissions: `media.update`

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | Yes | Unique identifier |


### Request Body

Content-Type: `multipart/form-data`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | string | Yes | Required |
| `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 |


### Responses

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


> **Notes:** - The CDN URL remains the same — existing references continue to work.
> 
> - Old CDN cache may take a few minutes to refresh.

### Examples

```bash
curl -X POST https://api.lynkow.com/v1/media/a1b2c3d4-e5f6-7890-abcd-ef1234567890/replace \
  -H "Authorization: Bearer $API_TOKEN" \
  -F "file=@new-hero-banner.jpg"
```

### Response Example

```json
{
  "data": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "filename": "new-hero-banner.jpg",
    "originalName": "new-hero-banner.jpg",
    "mimeType": "image/jpeg",
    "size": 310200,
    "width": 1920,
    "height": 1080,
    "alt": "Homepage hero banner",
    "url": "https://cdn.lynkow.com/sites/abc123/hero-banner.jpg",
    "variants": {
      "thumbnail": "https://cdn.lynkow.com/sites/abc123/hero-banner.jpg?w=150",
      "card": "https://cdn.lynkow.com/sites/abc123/hero-banner.jpg?w=400",
      "content": "https://cdn.lynkow.com/sites/abc123/hero-banner.jpg?w=800",
      "medium": "https://cdn.lynkow.com/sites/abc123/hero-banner.jpg?w=1200"
    },
    "createdAt": "2025-02-10T12:00:00.000Z",
    "updatedAt": "2025-04-06T12:00:00.000Z"
  }
}
```

---