Dokumentasi API
Unggah file lewat satu endpoint dan dapatkan link CDN langsung dari respons JSON.
Batas upload
| Minimal | 10 KB per file |
|---|---|
| Maksimal | 2 GB per file |
| Masa simpan | 24 jam, setelah itu file dihapus otomatis |
Endpoint
| Method | POST |
|---|---|
| URL | __BASE__/api/upload |
| Content-Type | multipart/form-data |
| Field | file (boleh lebih dari satu) |
API bisa dipanggil langsung dari browser di domain lain (CORS terbuka).
Contoh gateway (cURL)
curl -X POST -F "file=@foto.png" __BASE__/api/upload
Respons sukses (200)
{
"success": true,
"count": 1,
"url": "__BASE__/tmp/a1b2c3d4e5f6.png",
"files": [
{
"name": "a1b2c3d4e5f6.png",
"originalName": "foto.png",
"size": 20480,
"mimetype": "image/png",
"url": "__BASE__/tmp/a1b2c3d4e5f6.png"
}
]
}
Respons error
| 400 | Tidak ada file, atau file lebih kecil dari 10 KB |
|---|---|
| 413 | File lebih besar dari 2 GB |
| 500 | Server gagal menyimpan file |
Bentuknya selalu { "success": false, "error": "pesan" }.
Contoh kode
JavaScript (browser atau Node 18+):
const fd = new FormData();
fd.append('file', fileInput.files[0]);
const res = await fetch('__BASE__/api/upload', { method: 'POST', body: fd });
const data = await res.json();
if (!data.success) throw new Error(data.error);
console.log(data.url);
Python:
import requests
with open("foto.png", "rb") as f:
r = requests.post("__BASE__/api/upload", files={"file": f})
print(r.json()["url"])
Uploader sederhana siap pakai
Salin kode ini ke halaman HTML mana pun. Setelah file dipilih dan tombol ditekan, link CDN muncul di bawahnya.
<input type="file" id="f">
<button id="b">Upload</button>
<p id="out"></p>
<script>
b.onclick = async () => {
if (!f.files[0]) return (out.textContent = 'Pilih file dulu');
const fd = new FormData();
fd.append('file', f.files[0]);
const res = await fetch('__BASE__/api/upload', { method: 'POST', body: fd });
const data = await res.json();
out.textContent = data.success ? data.url : data.error;
};
</script>