TypeScript SDK

File & Folder CRUD Management

Full CRUD operations for files and virtual folders: browse hierarchies, rename/move assets with automatic storage synchronization, replace binary files in-place, and perform atomic deletions.

Listing Files & Folders (`listContents`)

Retrieve all files, folders, and breadcrumbs in a project root or within a specific virtual subfolder:

examples/list.ts
import { Cloudizero } from "@cloudizero/sdk";

const cz = new Cloudizero({ apiKey: process.env.CLOUDIZERO_API_KEY! });

// Daftar konten root direktori
const rootContents = await cz.storage.listContents({
  projectId: "prj_LXAlEW70v24YSc0y",
});

console.log("Root Folders:", rootContents.folders);
console.log("Root Files:", rootContents.files);

// Daftar konten subfolder spesifik berdasarkan folderId
const folderContents = await cz.storage.listContents({
  projectId: "prj_LXAlEW70v24YSc0y",
  folderId: "fld_ARaZjwdP...",
});

console.log("Current Breadcrumbs:", folderContents.breadcrumbs);

Fetching Asset Metadata (`getFile`)

Fetch relational metadata and obtain a presigned download URL for private assets:

examples/get-file.ts
// Mengambil metadata file dan tautan unduhan presigned sementara
const { file, downloadUrl } = await cz.storage.getFile("fil_tsvSl4yY...");

console.log("File Name:", file.name);
console.log("Size:", file.size);
console.log("Direct Download:", downloadUrl);
console.log("Thumbnail URL:", file.thumbnailUrl);

Updating & Replacing Files (`updateFile` & `replaceFile`)

Rename files, move them across folders, or replace their binary payload in-place while preserving the same fileId:

examples/update-file.ts
// 1. Pembaruan Metadata (Ubah nama file atau pindahkan ke folder lain)
// Otomatis memindahkan objek terkait di penyimpanan untuk sinkronisasi key & URL CDN
const renamedFile = await cz.storage.updateFile({
  fileId: "fil_tsvSl4yY...",
  name: "hero-banner-2026.webp",
  folderId: "fld_ARaZjwdP...", // atau null / "root" untuk pindah ke root proyek
});

// 2. Penggantian Biner In-Place (Timpa konten file dengan mempertahankan fileId yang sama)
const replacedFile = await cz.storage.replaceFile({
  fileId: "fil_tsvSl4yY...",
  file: newFileBuffer,
  fileName: "hero-banner-v2.webp",
  mimeType: "image/webp",
  onProgress: ({ percent }) => console.log(`Mengganti: ${percent}%`),
});

Parameters (`UpdateFileOptions`)

PropertyTypeDefaultDescription
fileId*requiredstring—Prefixed ID of the target file to update (e.g. 'fil_...').
namestring—New file name. Automatically moves the underlying storage object key to match.
folderIdstring | null—Target folder ID (e.g. 'fld_...', or null / 'root'). Automatically moves the storage object key.
isTrashboolean—Soft-delete trash status flag.
fileFile | Blob | Buffer | Uint8Array—Optional new binary payload to overwrite the file content in storage.
mimeTypestring—Updated MIME type when replacing file binary.
onProgress({ loaded, total, percent }) => void—Upload progress callback when replacing binary content.

Client Direct Upload via Presigned URL (`createPresignedUpload` & `completeUpload`)

Generate short-lived signed upload URLs allowing client-side browsers or mobile apps to upload binary payloads directly to the Cloudizero Storage Engine without server egress or memory bottlenecks:

examples/presigned-upload.ts
// 1. Backend: Buat tiket unggah presigned berdurasi terbatas
const ticket = await cz.storage.createPresignedUpload({
  projectId: "prj_LXAlEW70v24YSc0y",
  fileName: "podcast-episode.mp3",
  fileSize: 1024 * 1024 * 45, // 45 MB
  mimeType: "audio/mpeg",
});

// Kembalikan 'ticket' ke frontend:
// { uploadUrl, fileId, storageKey, finalFileName }

// 2. Browser / Client: Unggah biner langsung ke Cloudizero Storage Engine via PUT
// await fetch(ticket.uploadUrl, { method: "PUT", body: audioFile, headers: { "Content-Type": audioFile.type } });

// 3. Backend: Rekam metadata dan finalisasi aset di katalog Cloudizero
const file = await cz.storage.completeUpload({
  fileId: ticket.fileId,
  projectId: "prj_LXAlEW70v24YSc0y",
  fileName: ticket.finalFileName,
  mimeType: "audio/mpeg",
  fileSize: 1024 * 1024 * 45,
  storageKey: ticket.storageKey,
});

Automated WebP Image Optimization (optimize: "webp")

Synchronously transcode raster images (JPEG/PNG) to WebP at rest upon upload to save up to 75% storage quota with immediately deliverable CDN URLs:

examples/auto-optimize.ts
// 1. Shorthand: Automatically transcode raster images (JPEG/PNG) to WebP at rest (default quality 85)
const optimized = await cz.storage.upload({
  projectId: "prj_LXAlEW70v24YSc0y",
  file: imageBuffer,
  fileName: "hero-banner.jpg",
  optimize: "webp", // or optimize: true
});

console.log(optimized.name); // "hero-banner.webp"
console.log(optimized.mimeType); // "image/webp"
console.log(optimized.url); // "https://cdn.cloudizero.com/.../hero-banner.webp"

// 2. Granular Control: Customize compression quality (1 - 100)
const customOptimized = await cz.storage.upload({
  projectId: "prj_LXAlEW70v24YSc0y",
  file: pngBuffer,
  fileName: "product-preview.png",
  optimize: {
    format: "webp",
    quality: 80,
  },
});
Non-raster assets such as PDFs, SVGs, or videos are gracefully preserved without transcode. Corrupted image buffers automatically fall back to raw storage without interrupting your upload pipeline.

Virtual Folder CRUD (`createFolder`, `updateFolder`, `deleteFolder`)

Create, inspect, rename, move, and recursively delete virtual folders via the SDK:

examples/folders-crud.ts
// 1. Buat folder virtual
const folder = await cz.storage.createFolder({
  projectId: "prj_LXAlEW70v24YSc0y",
  name: "Marketing Assets",
  parentId: null, // opsional: parent folder ID untuk folder bersarang
});

// 2. Ambil informasi folder atau daftar folder
const folderInfo = await cz.storage.getFolder(folder.id);
const rootFolders = await cz.storage.listFolders({
  projectId: "prj_LXAlEW70v24YSc0y",
  parentId: "root",
});

// 3. Ubah nama atau pindahkan folder (otomatis sinkronisasi subfolder dan storage key)
const updatedFolder = await cz.storage.updateFolder({
  folderId: folder.id,
  name: "Brand & Marketing",
  parentId: null,
});

// 4. Hapus folder (menghapus subfolder dan objek penyimpanan secara rekursif)
const deleted = await cz.storage.deleteFolder(folder.id);
console.log(`Dihapus ${deleted.deletedFoldersCount} folder dan ${deleted.deletedFilesCount} file`);

Folder SDK Methods

PropertyTypeDefaultDescription
createFolder(options)*requiredCreateFolderOptions => Promise<StorageFolder>—Creates a folder in a project ({ projectId, name, parentId?, path? }).
getFolder(folderId)*requiredstring => Promise<StorageFolder>—Fetches a single folder record by its ID (e.g. 'fld_...').
listFolders(options)*requiredListFoldersOptions => Promise<StorageFolder[]>—Lists folders in a project directory ({ projectId, parentId? }).
updateFolder(options)*requiredUpdateFolderOptions => Promise<StorageFolder>—Renames or moves a folder ({ folderId, name?, parentId? }) and cascades storage keys.
deleteFolder(folderId)*requiredstring => Promise<DeleteFolderResult>—Recursively deletes a folder, its subfolders, and all contained storage objects.

Document Intelligence & PDF Extraction (`getFilePages` & `extractPdfPages`)

Access extracted high-resolution page previews, thumbnails, and document chapter outlines for multi-page documents (such as PDF), or trigger extraction pipelines programmatically:

examples/pdf-extraction.ts
// 1. Dapatkan daftar halaman, dimensi, URL CDN, dan bab dokumen PDF
const doc = await cz.storage.getFilePages("fil_tsvSl4yYKEOlO4KN");

console.log(`Total Halaman: ${doc.pageCount}`);
console.log("Status Pemrosesan:", doc.processingStatus);
console.log("Thumbnail Dokumen:", doc.thumbnailUrl);
console.log("Halaman Pertama:", doc.pages[0]?.url);
console.log("Daftar Bab:", doc.chapters);

// 2. Memicu antrean ekstraksi halaman PDF (asinkron)
const job = await cz.storage.extractPdfPages("fil_tsvSl4yYKEOlO4KN");
console.log("Status Antrean:", job.message);

Hybrid Multimodal Search (`search`)

Perform natural language search combining 768-dimensional vector semantic similarity with precise keyword matching across project assets:

examples/search.ts
// Pencarian multimodal hibrida (vektor semantik + kata kunci)
const searchResults = await cz.storage.search({
  projectId: "prj_LXAlEW70v24YSc0y",
  query: "sunset over the beach with palm trees",
});

console.log(`Mode Pencarian: ${searchResults.mode} (${searchResults.totalCount} hasil)`);

searchResults.results.forEach((match) => {
  console.log(`- ${match.name} [Skor: ${match.similarityScore}, Tipe: ${match.matchType}]`);
  console.log(`  CDN URL: ${match.url}`);
});

AI Visual Describe & WCAG Alt-Text (`describeImage`)

Analyze image assets with multimodal AI to automatically generate accessible WCAG alt-text, SEO categorical tags, descriptive visual summaries, and dominant color palettes:

examples/ai-describe.ts
// Analisis visual AI untuk teks alt WCAG, tag SEO, dan palet warna
const aiResult = await cz.storage.describeImage("fil_tsvSl4yYKEOlO4KN", {
  locale: "id", // atau "en" untuk bahasa Inggris
  force: false,
});

console.log("Teks Alt WCAG:", aiResult.altText);
console.log("Tag SEO:", aiResult.aiMetadata.tags);
console.log("Deskripsi Visual:", aiResult.aiMetadata.description);
console.log("Palet Warna Dominan:", aiResult.aiMetadata.dominantColors);

Dynamic Edge CDN Image Transformations (`getCdnUrl`)

Generate clean, authoritative CDN URLs with on-the-fly resizing, quality compression, and modern format conversions executed directly at Cloudizero's global edge network:

examples/cdn-transformations.ts
// 1. Dapatkan URL CDN asli untuk aset penyimpanan
const originalUrl = cz.storage.getCdnUrl("usr_IIZHBI7BIsUY7IOL/prj_LXAlEW70v24YSc0y/banner.png");
console.log("Original CDN URL:", originalUrl);
// => https://cdn.cloudizero.com/usr_IIZHBI7BIsUY7IOL/prj_LXAlEW70v24YSc0y/banner.png

// 2. Transformasi gambar dinamis di edge (lebar, tinggi, kualitas, format WebP)
const optimizedThumb = cz.storage.getCdnUrl("usr_IIZHBI7BIsUY7IOL/prj_LXAlEW70v24YSc0y/banner.png", {
  width: 400,
  height: 300,
  quality: 80,
  format: "webp",
  fit: "cover",
});
console.log("Optimized Thumbnail URL:", optimizedThumb);
// => https://cdn.cloudizero.com/usr_IIZHBI7BIsUY7IOL/prj_LXAlEW70v24YSc0y/banner.png?w=400&h=300&q=80&format=webp&fit=cover

Account Profile & Real-time Quota Inspection (`cz.getProfile`)

Programmatically inspect your account details, active subscription tier, storage capacity used, and remaining quota:

examples/account-profile.ts
// Periksa profil akun, tier paket langganan, dan pemakaian kuota waktu-nyata
const profile = await cz.getProfile();

console.log(`Paket Langganan: ${profile.plan} (${profile.isTrial ? "Trial Aktif" : "Reguler"})`);
console.log(`Kapasitas Terpakai: ${profile.stats.totalStorageBytes} / ${profile.limits.storageBytes} byte (${profile.stats.storagePercent}%)`);
console.log(`Sisa Penyimpanan: ${profile.stats.remainingStorageBytes} byte`);
console.log(`Total Proyek: ${profile.stats.projectsCount} / ${profile.limits.maxProjects}`);
console.log(`Total File: ${profile.stats.filesCount}`);

Project Lifecycle Management (`projects`)

Manage your project boundaries directly using the SDK: list, create, update, and delete projects.

examples/projects-crud.ts
// 1. List all accessible projects
const projects = await cz.projects.list();

// 2. Create a new project container (requires Global Access API key)
const newProject = await cz.projects.create({
  name: "Mobile App Assets",
  description: "Asset bucket for mobile application",
});

// 3. Update project details
const updated = await cz.projects.update(newProject.id, {
  name: "Mobile App Production Assets",
});

// 4. Reorder projects display order
await cz.projects.reorder([newProject.id, "prj_LXAlEW70v24YSc0y"]);

// 5. Delete project permanently with all contained files and folders
const res = await cz.projects.delete(newProject.id);
console.log(res.message);

Permanently Deleting Assets (`deleteFile` & `batchDelete`)

Deleting an asset is atomic: Cloudizero simultaneously purges the binary object from storage and removes its record from the database. You can delete single files with `deleteFile`, or multiple files and folders in one batch operation with `batchDelete` which recursively cleans up all nested folder subtrees.

examples/delete.ts
// Hapus file secara permanen dari penyimpanan dan database
const res = await cz.storage.deleteFile("fil_tsvSl4yYKEOlO4KN");

if (res.success) {
  console.log("Aset berhasil dihapus:", res.message);
}

Batch File & Folder Deletion (`batchDelete`)

examples/batch-delete.ts
// Batch delete multiple files and folders atomically in a single request
const batchRes = await cz.storage.batchDelete({
  projectId: "prj_LXAlEW70v24YSc0y",
  fileIds: ["fil_tsvSl4yYKEOlO4KN", "fil_ARaZjwdPpUqXhDHf"],
  folderIds: ["fld_subfolder_id"],
});

console.log(`Purged ${batchRes.deleted.totalPurgedFilesCount} total files across ${batchRes.deleted.explicitFoldersCount} folders.`);
Irreversible Action
Deleted files and folders cannot be recovered. Ensure you prompt for confirmation in user interfaces before triggering deletion.