C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • WebSockets
  • Task Scheduling
  • Queues
  • Job Batches
  • Caching
  • Events
  • Broadcasting
  • Notifications
  • SMS Channels
  • File Storage
  • Payment
  • Search
  • Security
  • Security Comparison
  • Performance
  • HTTP/2 Support
  • Deployment

File Storage

CanxJS provides a powerful file storage abstraction called "Flydrive". Easily switch between local disk, S3, or R2 without changing your code.

Configuration

Storage configuration is located in src/config/app.ts. You can define multiple "disks" using different drivers.

typescript
export const config = {
  storage: {
    default: 'local',
    disks: {
      local: {
        driver: 'local',
        root: './storage/app'
      },
      s3: {
        driver: 's3',
        key: process.env.AWS_ACCESS_KEY_ID,
        secret: process.env.AWS_SECRET_ACCESS_KEY,
        region: process.env.AWS_DEFAULT_REGION,
        bucket: process.env.AWS_BUCKET,
      }
    }
  }
}

Basic Usage

The storage facade allows you to interact with your configured disks.

typescript
import { storage } from 'canxjs';

// Write to default disk
await storage.put('avatars/1.jpg', fileContent);

// Write to specific disk
await storage.disk('s3').put('avatars/1.jpg', fileContent);

// Check existence
if (await storage.exists('file.jpg')) {
    // ...
}

// Get URL
const url = storage.url('avatars/1.jpg');

File Uploads

CanxJS simplifies file uploads with the handleUpload helper, which handles validation, naming, and storage automatically.

typescript
import { handleUpload } from 'canxjs';

class UserController extends Controller {
  @Post('/avatar')
  async uploadAvatar(req: CanxRequest) {
    const file = await handleUpload(req, 'avatar', {
        directory: 'avatars',
        allowedTypes: ['image/jpeg', 'image/png'],
        maxSize: 1024 * 1024 * 5 // 5MB
    });

    if (!file) throw new Error('No file uploaded');

    return { url: file.url };
  }
}

API Reference

Methods

  • put(path, content)
  • get(path)
  • exists(path)
  • delete(path)
  • copy(from, to)
  • move(from, to)
  • url(path)
  • size(path)
  • mimeType(path)