Update File
Updates an existing file's metadata.
HTTP Request
PATCH/api/media/files/:id
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- 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}'Status Codes
| Code | Description |
|---|---|
| 200 | File updated successfully |
| 400 | Bad request — invalid input |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 404 | File not found |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the file |
| type | String | File type (read-only, auto-detected) |
| user | Object | User who uploaded the file with id, username, full_name |
| f | String | File URL/path |
| name | String | Original filename |
| description | String | File description |
| size | Integer | File size in bytes (read-only) |
| human_readable_size | String | Human-readable file size (e.g., "2.5 MB") |
| width | Integer | Image width in pixels (images only, read-only) |
| height | Integer | Image height in pixels (images only, read-only) |
| mode | String | Image color mode (images only, read-only) |
| created_at | String (ISO 8601) | Timestamp when file was uploaded |
| updated_at | String (ISO 8601) | Timestamp when file was last updated |
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