import { StorageClient } from '@dcd-sdk/storage-client';
const storage = new StorageClient({
endpoint: process.env.DCD_STORAGE_ENDPOINT!,
apiKey: process.env.DCD_STORAGE_API_KEY!,
});
// 1. List assets in a folder
const result = await storage.listFiles({
folder: 'avatars',
limit: 20,
page: 1,
});
console.log(`Found ${result.pagination.total} files:`, result.data.files);
// 2. Permanently delete an asset
const deleted = await storage.delete('avatars/old-photo.jpg');
console.log('File deleted:', deleted);The SDK provides complete administration methods to query, inspect, and clean up files stored on your DevCloudDesk Storage Server.
1. Listing Files with Pagination#
Query your storage cluster with pagination and optional folder filtering:
const response = await storage.listFiles({
folder: 'products',
limit: 25,
page: 1,
});
console.log('Total files:', response.pagination.total);
for (const file of response.data.files) {
console.log(`- ${file.publicId} (${file.format}, ${file.size} bytes) -> ${file.url}`);
}Pagination Object Structure:
json{ "page": 1, "limit": 25, "total": 142, "totalPages": 6, "hasNext": true, "hasPrev": false }
2. Inspecting a Single Asset's Metadata#
Fetch stored dimensions, MIME type, file size, storage driver, and CDN URLs for a specific asset using getFile() (or getResource()):
// Using clean getFile alias (or storage.getResource):
const asset = await storage.getFile('avatars/user-99.jpg');
console.log('Format:', asset.format); // "jpg"
console.log('Dimensions:', asset.width, asset.height); // 1200, 800
console.log('Access:', asset.access); // "public"
console.log('Driver:', asset.storageDriver);// "local" or "s3"3. Deleting Assets (delete & destroy)#
Permanently removes the original file from disk (or S3/R2) and automatically purges all cached transformation variants across the cluster:
// Delete single asset:
const success = await storage.delete('avatars/user-99.jpg');
// Or use the destroy alias (Cloudinary style):
await storage.destroy('avatars/user-99.jpg');4. Purging Image Transformation Cache On Demand#
If you have updated stylesheets, modified default transformation parameters, or want to reclaim NVMe disk space without deleting any uploaded originals, purge the derived transformation cache:
const result = await storage.purgeCache();
console.log(`Purged ${result.purgedCount} cached image variants.`);5. Updating Asset Access Mode (public $\leftrightarrow$ private)#
You can change an existing asset between public and private access without re-uploading the file:
// Make an invoice private so it requires signed URLs to download:
await storage.api.update('invoices/inv-2026-001.pdf', { access: 'private' });Next Steps#
- Direct Browser Uploads →: Offload uploads from client browsers directly to your storage cluster.
- Securing Private Files →: Generate expiring download tokens.
- Cloudinary Drop-In Migration →: Migrate an existing Cloudinary codebase in minutes.