Skip to main content

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

ParameterTypeRequiredDescription
idIntegerYesUnique ID of the file

Request Body

FieldTypeRequiredDescription
nameStringNoFilename
descriptionStringNoFile description
fStringNoFile URL/path

Example Requests

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())

Response Fields

FieldTypeDescription
idIntegerUnique ID of the file
typeStringFile type(Choices)
userObjectUser who uploaded the file with id, username, full_name (nullable)
fStringFile URL/path
nameStringOriginal filename (nullable)
descriptionStringFile description (nullable)
sizeIntegerFile size in bytes (nullable)
human_readable_sizeStringHuman-readable file size (e.g., "2.5 MB", nullable)
widthIntegerImage width in pixels (images only, nullable)
heightIntegerImage height in pixels (images only, nullable)
modeStringImage color mode (images only, nullable)
created_atString (ISO 8601)Timestamp when file was uploaded
updated_atString (ISO 8601)Timestamp when file was last updated
thumbnailsList of thumbnail objectsthumbnails of the image

Thumbnail Data Structure

FieldTypeDescription
idIntegerUnique ID of the thumbnail (unique)
fStringURL to access the thumbnail file
sizeIntegerFile size in bytes (nullable)

*** User Object Structure

FieldTypeDescription
idIntegerUnique id of the uploader user
usernameStringUsername of the user
full_nameStringFull 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