Skip to main content

Upload a media 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 with FilePermission or Admin
  • Permission Code: 3801
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Request Body

FieldTypeRequiredDescription
fFileYesFile to upload (multipart/form-data)
nameStringNoCustom filename (defaults to original filename)
descriptionStringNoFile description

Example Requests

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

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
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": 10,
"type": "image",
"user": {
"id": 1,
"username": "BehroozGhorbani",
"full_name": "بهروز قربانی"
},
"f": "http://127.0.0.1:8000/media/core_media/2025/12/22/Fantasticheskie_kartinki_dlja_monitora_68_68.jpg",
"name": "slipknot member chris fehn",
"description": "some description for image if required",
"size": 1728593,
"human_readable_size": "1.65 MB",
"width": 2560,
"height": 1600,
"mode": "RGB",
"created_at": "2025-12-22T17:43:06.351315Z",
"updated_at": "2025-12-22T17:43:06.351324Z",
"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

    • 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
    • The user is automatically set to the current authenticated user
    • Thumbnails are auto-generated in four sizes for image-type files