Skip to main content

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

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

Status Codes

CodeDescription
200File updated successfully
400Bad request — invalid input
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404File not found
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the file
typeStringFile type (read-only, auto-detected)
userObjectUser who uploaded the file with id, username, full_name
fStringFile URL/path
nameStringOriginal filename
descriptionStringFile description
sizeIntegerFile size in bytes (read-only)
human_readable_sizeStringHuman-readable file size (e.g., "2.5 MB")
widthIntegerImage width in pixels (images only, read-only)
heightIntegerImage height in pixels (images only, read-only)
modeStringImage color mode (images only, read-only)
created_atString (ISO 8601)Timestamp when file was uploaded
updated_atString (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