Ready-to-use snippets that hit the live Tonta upload/delete endpoints.
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:
files = {"file": f}
response = requests.post(url, headers=headers, files=files)
if response.ok:
data = response.json()
print("Upload successful:", data["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
});
const data = await res.json();
setUrl(data.link);
} catch (err) {
console.error(err);
} finally {
setUploading(false);
}
};
return (
{uploading && Uploading…
}
{url &&
}
);
}
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
});
try {
const response = await fetch('https://tonta.io/uploader/upload.php', {
method: 'POST',
headers: { 'X-API-Key': 'YOUR_API_KEY', ...formData.getHeaders() },
body: formData
});
const data = await response.json();
res.json({ success: true, link: data.link });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
app.listen(3000, () => console.log('Server running on port 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']
)
]
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (!empty($data['link'])) {
echo 'Upload successful: ' . $data['link'];
} else {
echo 'Upload failed: ' . $response;
}
}
?>
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 docs or walkthrough guides for deeper dives.