Upload File
Uploads a new file to the system. The file will be associated with the authenticated user.
HTTP Request
POST/api/media/files
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| f | File | Yes | File to upload (multipart/form-data) |
| name | String | No | Custom filename (defaults to original filename) |
| description | String | No | File description |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Upload a file
4with open('image.jpg', 'rb') as file:
5 response = requests.post('http://www.example.com/api/media/files',
6 files={
7 'f': ('image.jpg', file, 'image/jpeg')
8 },
9 data={
10 'name': 'Profile Picture',
11 'description': 'User profile avatar'
12 },
13 headers={'Authorization': 'Token <your_api_key>'}
14 )
15print(response.json())
16
17# Upload with minimal data
18with open('document.pdf', 'rb') as file:
19 response = requests.post('http://www.example.com/api/media/files',
20 files={
21 'f': ('document.pdf', file, 'application/pdf')
22 },
23 headers={'Authorization': 'Token <your_api_key>'}
24 )
25print(response.json())1# Upload a file
2curl -X POST "http://www.example.com/api/media/files" \
3-H "Authorization: Token <your_api_key>" \
4-F "f=@image.jpg" \
5-F "name=Profile Picture" \
6-F "description=User profile avatar"
7
8# Upload with minimal data
9curl -X POST "http://www.example.com/api/media/files" \
10-H "Authorization: Token <your_api_key>" \
11-F "f=@document.pdf"Status Codes
| Code | Description |
|---|---|
| 201 | File uploaded successfully |
| 400 | Bad request — invalid file or input |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 413 | File too large |
| 415 | Unsupported media type |
| 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
- File upload requires multipart/form-data content type
- File type is automatically detected based on content and MIME type
- For image files, dimensions and color mode are automatically extracted
- Files are associated with the authenticated user who uploads them
- File size is automatically calculated and stored in both bytes and human-readable format
- Only the 'f' field is required; name and description are optional
- If name is not provided, the original filename will be used