The convert endpoint transforms a media file from one format to another and saves the result as a new file underDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-var-cms/llms.txt
Use this file to discover all available pages before exploring further.
MEDIA_ROOT/converted/. The source file is never modified. Supported media categories include images (via Pillow), audio and video (via ffmpeg), and PDF-to-image extraction (via pdf2image + Poppler). Each category requires its own dependency to be available in the environment.
Endpoint
Authentication
Login required. Requests must carry a valid authenticated Django session. The endpoint is protected by Django’slogin_required decorator.
Supported Conversions
| Media Type | Source Formats | Target Formats | Dependency |
|---|---|---|---|
| Image | jpeg, jpg, png, webp, bmp, tiff, gif | jpeg, jpg, png, webp, bmp, tiff, gif | Pillow |
| Audio | mp3, wav, ogg, flac, aac, m4a | mp3, wav, ogg, flac, aac, m4a | ffmpeg |
| Video | mp4, webm, avi, mov, mkv | mp4, webm, avi, mov, mkv | ffmpeg |
| PDF → Images | pdf | png, jpg, jpeg | pdf2image + Poppler |
Audio and video conversion uses ffmpeg via
subprocess. The ffmpeg binary must be accessible on the system PATH of the process running Django. PDF conversion uses pdf2image (which wraps Poppler’s pdftoppm). These are optional — the endpoint returns a clear install_hint in the error body if a required tool is missing.Request Parameters
Send parameters asapplication/x-www-form-urlencoded (standard HTML form POST body).
Relative media path of the source file inside
MEDIA_ROOT. Do not include the MEDIA_URL prefix.Example: var_cms/images/2024/01/photo.pngDesired output file extension (without the leading dot). The value is lowercased and any leading
. is stripped automatically. The endpoint uses this to determine both the conversion pathway and the output filename.Examples: webp, mp3, mp4, pngResponse
Image success — 200 OK
Absolute media URL of the converted file. Example:
/media/converted/7b3c9a12ef56.webpRelative storage path of the output file within
MEDIA_ROOT. Example: converted/7b3c9a12ef56.webpAlways
"image" for image conversions.Audio / Video success — 200 OK
Absolute media URL of the converted file.
Relative storage path of the output file within
MEDIA_ROOT."audio" when the target format is an audio format; "video" when it is a video format.PDF success — 200 OK
Always
"pdf_pages" for PDF-to-image conversions.Ordered array of media URLs, one per extracted page. Each page is saved as a separate PNG file under
MEDIA_ROOT/converted/.Total number of pages extracted from the PDF.
Error Responses
Human-readable error message. Returned alongside an optional
install_hint field for dependency errors.| Status | error value | install_hint | Cause |
|---|---|---|---|
400 | "file_path and target_fmt required" | — | One or both required POST parameters were missing or empty. |
400 | "Unsupported conversion: X → Y" | — | The source/target format combination is not handled by any converter. |
404 | "File not found" | — | The resolved path does not exist inside MEDIA_ROOT. |
500 | "Pillow not installed" | — | Pillow is missing; required for image conversions. |
500 | "ffmpeg not found. Install with: sudo apt install ffmpeg" | "sudo apt install ffmpeg" | The ffmpeg binary is not on the system PATH. |
500 | "pdf2image not installed. Run: uv add pdf2image" | "uv add pdf2image" | The pdf2image package is missing; required for PDF conversions. |
Requirements & Optional Extras
Pillow is required for image conversion. Audio/video conversion and PDF extraction are opt-in dependencies:Example
Request
Response
PDF Example Response
Conversion Details
Images
Pillow opens the source file, converts to the target format, and saves at quality90. Images in RGBA or P mode are automatically converted to RGB when the target format is JPEG. Output files are saved to converted/{uuid.hex[:12]}.{ext} via Django’s default_storage.
Audio & Video
ffmpeg is invoked viasubprocess with a -y -i <source> <output> command and a 120-second timeout. The converted file is written to a temporary path, read into memory, then saved via Django’s default_storage. The type field in the response is "audio" if the target format is in the audio formats set, otherwise "video".
pdftoppm at 150 DPI, producing one PIL Image object per page. Each page is saved as a PNG to MEDIA_ROOT/converted/ and its URL is appended to the pages array.