Skip to main content
Sonamu provides a unified file storage system based on Flydrive. You can use the local file system (fs) and AWS S3 with the same interface, and manage multiple disks as needed.

Why Storage Manager?

The Problem

Problems:
  • Different code for each environment
  • Code changes required when switching drivers
  • URL generation logic is scattered

Using Storage Manager

Benefits:
  • Driver-independent code
  • Switch drivers by just changing configuration
  • Consistent URL generation

Core Concepts

Storage Manager

A manager that handles multiple Disks.

Disk

A Disk is a single driver instance that stores files.

Basic Configuration

sonamu.config.ts

Configuration elements:
  • default: Name of the default disk to use
  • drivers: Driver factories by disk name

Using Disks

Default Disk

Specific Disk

Managing Multiple Disks

Multi-Disk Configuration

Using Disks by Purpose

Environment-based Strategies

Development/Production Separation

Using local file system
Benefits:
  • No AWS account needed
  • Fast development
  • No cost

Hybrid Strategy

Practical Examples

1. Profile Photo Upload

2. Multiple File Upload

3. Separation by Disk

Storage Manager API

use(diskName?)

Returns a disk instance.
Return value: Disk instance (Flydrive)

defaultDisk

Returns the default disk name.

Disk API (Flydrive)

The Disk returned by Storage Manager is a Flydrive Disk instance.

Key Methods

Cautions

Cautions when using Storage Manager:
  1. Environment variables required: AWS credentials needed for S3
  2. Disk name typos: Error when using non-existent disk
  3. Path separator: Use / for platform independence
  4. URL builder required: fs driver requires urlBuilder configuration
  5. Lazy Initialization: Disks are initialized on first use

Next Steps

Storage Drivers

Detailed fs, S3 driver configuration

File Operations

File upload and download

URL Builder

Generating file URLs