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:
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:
// 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:
// 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`)
| Property | Type | Default | Description |
|---|---|---|---|
| fileId*required | string | — | Prefixed ID of the target file to update (e.g. 'fil_...'). |
| name | string | — | New file name. Automatically moves the underlying storage object key to match. |
| folderId | string | null | — | Target folder ID (e.g. 'fld_...', or null / 'root'). Automatically moves the storage object key. |
| isTrash | boolean | — | Soft-delete trash status flag. |
| file | File | Blob | Buffer | Uint8Array | — | Optional new binary payload to overwrite the file content in storage. |
| mimeType | string | — | 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:
// 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:
// 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,
},
});Virtual Folder CRUD (`createFolder`, `updateFolder`, `deleteFolder`)
Create, inspect, rename, move, and recursively delete virtual folders via the SDK:
// 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
| Property | Type | Default | Description |
|---|---|---|---|
| createFolder(options)*required | CreateFolderOptions => Promise<StorageFolder> | — | Creates a folder in a project ({ projectId, name, parentId?, path? }). |
| getFolder(folderId)*required | string => Promise<StorageFolder> | — | Fetches a single folder record by its ID (e.g. 'fld_...'). |
| listFolders(options)*required | ListFoldersOptions => Promise<StorageFolder[]> | — | Lists folders in a project directory ({ projectId, parentId? }). |
| updateFolder(options)*required | UpdateFolderOptions => Promise<StorageFolder> | — | Renames or moves a folder ({ folderId, name?, parentId? }) and cascades storage keys. |
| deleteFolder(folderId)*required | string => 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:
// 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:
// 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:
// 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:
// 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=coverAccount Profile & Real-time Quota Inspection (`cz.getProfile`)
Programmatically inspect your account details, active subscription tier, storage capacity used, and remaining quota:
// 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.
// 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.
// 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`)
// 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.`);