惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
B
Blog RSS Feed
Last Week in AI
Last Week in AI
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
雷峰网
雷峰网
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 司徒正美
U
Unit 42
量子位

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Convert Files Programmatically with a REST API (Py...
MegaConvert · 2026-05-01 · via DEV Community

MegaConvert

Tired of manually converting files? I built MegaConvert — a file conversion API that handles
300+ format pairs: documents, images, video, audio, ebooks, fonts, and more.

In this post I'll show you how to convert files programmatically in 3 steps using Python, JavaScript, or cURL.

## How It Works

Every conversion follows the same flow:

  1. POST your file to /convert
  2. Poll /status/{job_id} until it's done
  3. GET /download/{job_id} to grab the result

Base URL: https://megaconvert.io/api/v1
Auth: X-API-Key header

## cURL — Quick Test


bash
  # Step 1: Submit
  curl -X POST https://megaconvert.io/api/v1/convert \
    -H "X-API-Key: mc_your_key" \
    -F "file=@document.pdf" \
    -F "output_format=docx"

  # Response: {"job_id": "abc123", "status": "processing"}

  # Step 2: Check status
  curl https://megaconvert.io/api/v1/status/abc123 \
    -H "X-API-Key: mc_your_key"

  # Step 3: Download
  curl -O https://megaconvert.io/api/v1/download/abc123 \
    -H "X-API-Key: mc_your_key"

  Python Example

  import requests
  import time

  API_KEY = "mc_your_api_key_here"
  BASE = "https://megaconvert.io/api/v1"
  headers = {"X-API-Key": API_KEY}

  # Submit conversion
  with open("image.png", "rb") as f:
      r = requests.post(f"{BASE}/convert", headers=headers,
                        files={"file": f},
                        data={"output_format": "webp"})

  job_id = r.json()["job_id"]

  # Wait for completion
  while True:
      status = requests.get(f"{BASE}/status/{job_id}", headers=headers).json()["status"]
      if status == "completed":
          break
      time.sleep(2)

  # Download result
  result = requests.get(f"{BASE}/download/{job_id}", headers=headers)
  with open("image.webp", "wb") as f:
      f.write(result.content)

  JavaScript (Node.js)

  const fs = require('fs');
  const FormData = require('form-data');

  const API_KEY = 'mc_your_api_key_here';
  const BASE = 'https://megaconvert.io/api/v1';
  const headers = { 'X-API-Key': API_KEY };

  async function convertFile(inputPath, outputFormat) {
    const form = new FormData();
    form.append('file', fs.createReadStream(inputPath));
    form.append('output_format', outputFormat);

    // Submit
    const res = await fetch(`${BASE}/convert`, {
      method: 'POST',
      headers: { ...headers, ...form.getHeaders() },
      body: form
    });
    const { job_id } = await res.json();

    // Poll
    while (true) {
      const status = await fetch(`${BASE}/status/${job_id}`, { headers });
      const { status: s } = await status.json();
      if (s === 'completed') break;
      await new Promise(r => setTimeout(r, 2000));
    }

    // Download
    const download = await fetch(`${BASE}/download/${job_id}`, { headers });
    const buffer = Buffer.from(await download.arrayBuffer());
    fs.writeFileSync(`output.${outputFormat}`, buffer);
  }

  convertFile('document.pdf', 'docx');

  Built-in Tools

  Beyond format conversion, the API has processing tools:

  ┌────────────────┬────────────────────────────┐
  │      Tool      │        What it does        │
  ├────────────────┼────────────────────────────┤
  │ compress-pdf   │ Reduce PDF file size       │
  ├────────────────┼────────────────────────────┤
  │ merge-pdf      │ Combine multiple PDFs      │
  ├────────────────┼────────────────────────────┤
  │ compress-image │ Optimize image size        │
  ├────────────────┼────────────────────────────┤
  │ resize-image   │ Change dimensions          │
  ├────────────────┼────────────────────────────┤
  │ compress-video │ Reduce video file size     │
  ├────────────────┼────────────────────────────┤
  │ trim-video     │ Cut video segments         │
  ├────────────────┼────────────────────────────┤
  │ video-to-gif   │ Convert video clips to GIF │
  ├────────────────┼────────────────────────────┤
  │ extract-audio  │ Pull audio from video      │
  └────────────────┴────────────────────────────┘

  # Compress a PDF
  with open("large.pdf", "rb") as f:
      r = requests.post(f"{BASE}/tool", headers=headers,
                        files={"file": f},
                        data={"tool": "compress-pdf"})

  Supported Formats

  300+ conversion pairs across:
  - Documents: PDF, DOCX, XLSX, PPTX, ODT, CSV, HTML, RTF, TXT
  - Images: JPG, PNG, WebP, HEIC, GIF, BMP, TIFF, SVG
  - Video: MP4, WebM, AVI, MOV, MKV
  - Audio: MP3, WAV, OGG, FLAC, AAC
  - Ebooks: EPUB, MOBI, AZW3
  - And more: fonts, subtitles, archives, vector/CAD

  Full list: https://megaconvert.io/docs/api

  Pricing

  API access comes with the 12-month plan at $79/year — that's 100 requests/day, which works out to $0.003 per conversion.
  Compare that to CloudConvert ($0.02+) or Zamzar ($0.08+).

  Links

  - API Docs: https://megaconvert.io/docs/api
  - GitHub (examples + docs): https://github.com/rpnet/megaconvert-api
  - Try it free: https://megaconvert.io — 3 free conversions/day, no account needed

  ---
  If you have questions or want to see a specific integration example, drop a comment below. 
https://megaconvert.io/docs/api

Enter fullscreen mode Exit fullscreen mode