Upload a file → pick a target format → download the converted output. Works via web UI or JSON API.
- Image, video, audio, and PDF conversions (via ffmpeg & poppler).
- Safe uploads with size cap (50 MB) and MIME sniffing.
- Extension ↔ MIME validation, path sanitization, and strict static serving.
- Concurrency gate (3 concurrent jobs) + 150s conversion timeout.
- Security headers, request ID (
X-Request-ID), and graceful shutdown. - JSON or HTML responses (auto‑select via
Acceptheader).
Install the external tools first:
- ffmpeg (images / audio / video)
- poppler (for PDF → image/text via
pdftoppm/pdftotext)
macOS (Homebrew):
brew install ffmpeg popplerLinux (Debian/Ubuntu):
sudo apt-get update && sudo apt-get install -y ffmpeg poppler-utilsgo run .
# Server will start at http://localhost:3030Static assets:
- UI:
templates/index.html,templates/select_format.html - Uploaded files:
uploads/ - Converted files:
converted/(also served at/converted/…)
Images
- jpeg ↔ png ↔ webp ↔ bmp ↔ gif
- tiff → jpg/png
- gif → mp4/webm (animated GIF → video)
Video
- mp4 ↔ webm, mp4/webm → gif, any → mp3
Audio
- mp3 ↔ wav ↔ ogg ↔ flac; aac/m4a ↔ mp3/wav
Documents
- pdf → png/jpg/txt
- Upload a file
- Choose a target format (only valid options shown)
- Download the converted file
The server auto‑detects Accept: application/json and returns JSON.
POST /upload (multipart/form-data)
- Field:
file— the file to upload
curl -H "Accept: application/json" \
-F [email protected] \
http://localhost:3030/uploadResponse
{
"filename": "1730112345678_ab12cd_example.mp4",
"original": "example.mp4",
"formats": ["WEBM","AVI","MOV","GIF","MP3"]
}POST /convert (application/x-www-form-urlencoded or JSON)
- Params:
filename— server‑side stored name from/uploadoriginal— original filename (used to suggest download name)format— target extension (e.g.,webm,mp3,png)
curl -H "Accept: application/json" \
-X POST http://localhost:3030/convert \
-d "filename=1730112345678_ab12cd_example.mp4" \
-d "original=example.mp4" \
-d "format=webm"Response
{
"download": "/download?file=1730112345678_ab12cd_example.webm&name=example.webm",
"downloadName": "example.webm"
}GET /download?file=<stored>&name=<suggested>
Supports HEAD. Sets immutable caching & Content-Disposition for attachment.
- Upload limit: 50 MB (
maxUploadSize) - Conversion timeout: 150 s (
conversionTimeout) - Concurrency: 3 parallel conversions (
maxConcurrentConversions) - Security headers: CSP, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy
- Request ID: every response includes
X-Request-ID
Adjust these in the
constblock inmain.goif needed.
.
├─ templates/
│ ├─ index.html
│ └─ select_format.html
├─ static/ # optional CSS/JS
├─ uploads/ # runtime (gitignored)
├─ converted/ # runtime (gitignored)
└─ main.go
