Copy-paste snippets that hit the live Tonta upload and delete endpoints — pick your stack and go.
const formData = new FormData(); formData.append('file', document.querySelector('#file').files[0]); fetch('https://tonta.io/uploader/upload.php', { method: 'POST', headers: { 'X-API-Key': 'YOUR_API_KEY' }, body: formData }) .then(res => res.json()) .then(result => console.log('Uploaded:', result.link)) .catch(err => console.error('Upload failed', err));
import requests url = "https://tonta.io/uploader/upload.php" headers = {"X-API-Key": "YOUR_API_KEY"} with open("image.jpg", "rb") as f: response = requests.post(url, headers=headers, files={"file": f}) if response.ok: print("Upload successful:", response.json()["link"]) else: print("Upload failed:", response.text)
curl -X POST "https://tonta.io/uploader/upload.php" \ -H "X-API-Key: YOUR_API_KEY" \ -F "file=@/path/to/image.jpg"
import { useState } from 'react'; export default function ImageUpload() { const [uploading, setUploading] = useState(false); const [url, setUrl] = useState(''); const handleUpload = async (event) => { const file = event.target.files[0]; if (!file) return; setUploading(true); const formData = new FormData(); formData.append('file', file); try { const res = await fetch('https://tonta.io/uploader/upload.php', { method: 'POST', headers: { 'X-API-Key': 'YOUR_API_KEY' }, body: formData }); setUrl((await res.json()).link); } finally { setUploading(false); } }; return ( <div> <input type="file" onChange={handleUpload} /> {uploading && <p>Uploading…</p>} {url && <img src={url} alt="Uploaded" />} </div> ); }
const express = require('express'); const multer = require('multer'); const FormData = require('form-data'); const fetch = require('node-fetch'); const app = express(); const upload = multer({ storage: multer.memoryStorage() }); app.post('/upload', upload.single('file'), async (req, res) => { const formData = new FormData(); formData.append('file', req.file.buffer, { filename: req.file.originalname, contentType: req.file.mimetype }); const response = await fetch('https://tonta.io/uploader/upload.php', { method: 'POST', headers: { 'X-API-Key': 'YOUR_API_KEY', ...formData.getHeaders() }, body: formData }); res.json(await response.json()); }); app.listen(3000);
<?php $apiKey = 'YOUR_API_KEY'; $url = 'https://tonta.io/uploader/upload.php'; if ($_FILES['file']['error'] === UPLOAD_ERR_OK) { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["X-API-Key: $apiKey"], CURLOPT_POSTFIELDS => [ 'file' => new CURLFile( $_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['name'] ) ] ]); $data = json_decode(curl_exec($ch), true); curl_close($ch); echo $data['link'] ?? 'Upload failed'; }
curl -X POST "https://tonta.io/uploader/delete.php" \ -H "Content-Type: application/json" \ -H "X-API-Key: YOUR_API_KEY" \ -d '{ "smallids": ["rT2F6Dn_1920.jpg", "rT2F6Dn_1024.jpg"] }'
Explore the full reference docs or the developer guides for deeper dives.