API Documentation

Introduction

GitHub CDN provides a simple API for uploading files. You can use this API to integrate file hosting capabilities into your applications.

Base URL

https://cdn.apizell.web.id

All API endpoints are relative to this base URL.

Endpoints

Upload a File

POST /api/cdn/upload

Upload a file to the CDN. The file should be sent as form data with the key "file".

Example (JavaScript)

const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('https://cdn.apizell.web.id/api/cdn/upload', {
  method: 'POST',
  body: formData
})
.then(response => response.json())
.then(data => {
  console.log('Success:', data);
  // data.url contains the file URL
  // data.fullUrl contains the full URL with domain
})
.catch(error => {
  console.error('Error:', error);
});

Example (Node.js - ESM)

import fs from 'fs';
import axios from 'axios';
import FormData from 'form-data';

async function cdnzellUpload(filePath) {
    const form = new FormData();
    form.append("file", fs.createReadStream(filePath));

    try {
        const response = await axios.post(
            "https://cdn.apizell.web.id/api/cdn/upload", form, {
                headers: form.getHeaders(),
            });

        const data = response.data; 
        console.log("File uploaded:", data.fullUrl);
        return data;
    } catch (err) {
        console.error("Upload failed:", err.response?.data || err.message);
        throw err;
    }
}

// Example usage
cdnzellUpload("/path/to/your/file.jpg")
    .then((data) => console.log(data))
    .catch((err) => console.error(err));

Example (Node.js - CommonJS)

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

async function cdnzellUpload(filePath) {
    const form = new FormData();
    form.append("file", fs.createReadStream(filePath));

    try {
        const response = await axios.post(
            "https://cdn.apizell.web.id/api/cdn/upload", form, {
                headers: form.getHeaders(),
            });

        const data = response.data; 
        console.log("File uploaded:", data.fullUrl);
        return data;
    } catch (err) {
        console.error("Upload failed:", err.response?.data || err.message);
        throw err;
    }
}

// Example usage
cdnzellUpload("/path/to/your/file.jpg")
    .then((data) => console.log(data))
    .catch((err) => console.error(err));

Example (PHP)

<?php
$url = 'https://cdn.apizell.web.id/api/cdn/upload';
$file = new CURLFile('/path/to/your/file.jpg', 'image/jpeg', 'file.jpg');

$data = array('file' => $file);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);
echo "File URL: " . $result['fullUrl'];
?>

Example (Python)

import requests

url = 'https://cdn.apizell.web.id/api/cdn/upload'
files = {'file': open('image.jpg', 'rb')}

response = requests.post(url, files=files)
data = response.json()

print('Success:', data)
# data['url'] contains the file URL
# data['fullUrl'] contains the full URL with domain

Example (cURL)

curl -X POST \
  -F 'file=@/path/to/your/file.jpg' \
  https://cdn.apizell.web.id/api/cdn/upload

Response Format

All API responses are in JSON format. Here's an example of a successful file upload response:

{
  "success": true,
  "url": "/cdn/62e64b3b.jpg",
  "fullUrl": "https://cdn.apizell.web.id/cdn/62e64b3b.jpg",
  "sha": "bb3f0fd73b41a09dc753c57b280db15dd69039da",
  "fileName": "62e64b3b.jpg",
  "originalName": "image.jpg",
  "size": 1962850,
  "formattedSize": "1.87 MB",
  "type": "image/jpeg"
}

Error Handling

In case of an error, the API will return a JSON response with an error message:

{
  "error": "File too large. Maximum size is 20MB."
}

Rate Limits

The API has a rate limit of 100 requests per minute per IP address. If you exceed this limit, you'll receive a 429 Too Many Requests response.