Update File
Updates an existing media file's metadata.
HTTP Request
PATCH/api/media/files/:id
Authorization
Authorization
- Required: Yes
- Permission: Staff with FilePermission or Admin
- Permission Code: 3803
- Authentication: Token-based (Authorization: Token <your_api_key>)
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | Integer | Yes | Unique ID of the file |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| name | String | No | Filename |
| description | String | No | File description |
| f | String | No | File URL/path |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Partial update (PATCH)
4response = requests.patch('http://www.example.com/api/media/files/123',
5 json={
6 'name': 'Updated Profile Picture',
7 'description': 'Updated user avatar image'
8 },
9 headers={'Authorization': 'Token <your_api_key>'}
10)
11print(response.json())
12
13# Update only description
14response = requests.patch('http://www.example.com/api/media/files/123',
15 json={
16 'description': 'Company logo for marketing materials'
17 },
18 headers={'Authorization': 'Token <your_api_key>'}
19)
20print(response.json())
21
22# Full update (PUT)
23response = requests.put('http://www.example.com/api/media/files/123',
24 json={
25 'name': 'Company Logo',
26 'description': 'Official company logo',
27 'f': 'File path...'
28 },
29 headers={'Authorization': 'Token <your_api_key>'}
30)
31print(response.json())1# Partial update (PATCH)
2curl -X PATCH "http://www.example.com/api/media/files/123" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "name": "Updated Profile Picture",
7 "description": "Updated user avatar image"
8}'
9
10# Update only description
11curl -X PATCH "http://www.example.com/api/media/files/123" \
12-H "Authorization: Token <your_api_key>" \
13-H "Content-Type: application/json" \
14-d '{
15 "description": "Company logo for marketing materials"
16}'Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the file |
| type | String | File type(Choices) |
| user | Object | User who uploaded the file with id, username, full_name (nullable) |
| f | String | File URL/path |
| name | String | Original filename (nullable) |
| description | String | File description (nullable) |
| size | Integer | File size in bytes (nullable) |
| human_readable_size | String | Human-readable file size (e.g., "2.5 MB", nullable) |
| width | Integer | Image width in pixels (images only, nullable) |
| height | Integer | Image height in pixels (images only, nullable) |
| mode | String | Image color mode (images only, nullable) |
| created_at | String (ISO 8601) | Timestamp when file was uploaded |
| updated_at | String (ISO 8601) | Timestamp when file was last updated |
| thumbnails | List of thumbnail objects | thumbnails of the image |
Thumbnail Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the thumbnail (unique) |
| f | String | URL to access the thumbnail file |
| size | Integer | File size in bytes (nullable) |
*** User Object Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique id of the uploader user |
| username | String | Username of the user |
| full_name | String | Full name of the user (computed value from first and last name) |
Example Response
{
"id": 9,
"type": "text",
"user": {
"id": 14,
"username": "Shakira_Anderson47",
"full_name": "بهرام نوروزی"
},
"f": "http://127.0.0.1:8000/media/core_media/2025/12/22/askari.txt",
"name": "chris fehn",
"description": "some new description for file",
"size": 1408,
"human_readable_size": "1.38 KB",
"created_at": "2025-12-22T17:29:34.807896Z",
"updated_at": "2025-12-23T12:58:13.448082Z",
"thumbnails": [
{
"id": 313,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_64x64.jpg",
"size": 64
},
{
"id": 314,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_128x128.jpg",
"size": 128
},
{
"id": 315,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_512x512.jpg",
"size": 512
},
{
"id": 316,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_1080x1080.jpg",
"size": 1080
}
]
}
Notes
- Use PATCH for partial updates (recommended) - only send fields you want to change
- Use PUT for full updates - replaces all file metadata with provided values
- The following fields are read-only and cannot be updated: type, size, width, height, mode
- File type is automatically detected and cannot be modified
- Image dimensions and color mode are extracted automatically and cannot be changed
- Only metadata can be updated; to change the actual file, delete and re-upload
- For PUT requests, the name field becomes required
- Thumbnails are auto-updated for image-type files