Skip to main content

List Files

Retrieves a list of all files with filtering, searching, and ordering capabilities.

HTTP Request

GET/api/media/files

Authorization

Authorization

  • Required: Yes
  • Permission: Staff or Admin
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Query Parameters

ParameterTypeDefaultDescription
limitinteger10Number of results to return per page
offsetinteger0Number of results to skip before returning results
searchstringSearch term to filter results by id, name
orderingstringField to order results by (id, type, name, size, width, height, mode, created_at, updated_at, user__id, user__username, user__first_name, user__last_name, user__last_login)
typestringFilter by file type (pdf, text, image, document, compressed, spreadsheet, presentation, video, audio)
user_idintegerFilter by specific user ID who uploaded the file
size_minintegerMinimum file size in bytes
size_maxintegerMaximum file size in bytes
width_minintegerMinimum image width in pixels (applies to images only)
width_maxintegerMaximum image width in pixels (applies to images only)
height_minintegerMinimum image height in pixels (applies to images only)
height_maxintegerMaximum image height in pixels (applies to images only)
id_minintegerMinimum ID filter
id_maxintegerMaximum ID filter
created_datestringFilter by creation date (e.g., 2023-01-01)
updated_datestringFilter by last updated date (e.g., 2023-01-01)
created_fromstringFilter by creation date range start
created_tostringFilter by creation date range end
updated_fromstringFilter by last updated date range start
updated_tostringFilter by last updated date range end

Example Requests

1import requests
2
3# List all files
4response = requests.get('http://www.example.com/api/media/files', 
5  headers={'Authorization': 'Token <your_api_key>'}
6)
7print(response.json())
8
9# Search for files with filters
10response = requests.get('http://www.example.com/api/media/files', params={
11  'search': 'profile',
12  'type': 'image',
13  'size_min': 1024,
14  'ordering': '-created_at',
15  'limit': 20
16}, headers={'Authorization': 'Token <your_api_key>'})
17print(response.json())
18
19# Filter by user and image dimensions
20response = requests.get('http://www.example.com/api/media/files', params={
21  'user_id': 123,
22  'width_min': 800,
23  'height_min': 600,
24  'created_from': '2023-01-01'
25}, headers={'Authorization': 'Token <your_api_key>'})
26print(response.json())

Status Codes

CodeDescription
200Files retrieved successfully
401Unauthorized — authentication required
403Forbidden — insufficient permissions
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

    • width, height, and mode fields are only included in the response for image files
    • File type is automatically detected and set upon upload based on content and MIME type
    • Search works on file ID and name fields
    • Size filters work in bytes - use appropriate values for filtering by file size
    • Image dimension filters (width_min, width_max, height_min, height_max) only apply to image files
    • User object includes basic information about who uploaded the file