Skip to main content
Sonamu provides an integrated storage system for file uploads and storage. It supports local file system (fs) and AWS S3, and you can easily switch between them based on the environment.

Basic Structure

drivers

Defines the storage drivers to use. Two types are supported: "fs" (local file system) and "s3" (AWS S3). Type: Record<DriverKey, () => DriverContract> (DriverKey = "fs" | "s3")
When saving files, you explicitly specify which driver to use in the saveToDisk(diskName, key) call. To use different drivers per environment, branch at the code level using environment variables.

fs Driver

Stores files on the local file system. Suitable for development environments.

location

The directory path where files will be stored. Type: string (required)
Path example:

visibility

Sets the access permissions for files. Type: "public" | "private"
  • "public": Anyone can access via URL
  • "private": Only authenticated users can access

urlBuilder

Defines functions to generate file URLs.
generateURL: Generates the public URL for a file.
  • key: Unique key for the file (e.g., "profile-images/user-123.jpg")
  • Returns: Accessible URL
generateSignedURL: Generates a temporarily accessible signed URL.
  • key: Unique key for the file
  • expiresIn: Expiration time (seconds, optional)
  • Returns: Temporary URL

s3 Driver

Stores files on AWS S3. Suitable for production environments.

credentials

Sets AWS authentication credentials. Type: (required)
Always manage AWS credentials via environment variables. Never write them directly in code!
.env:

region

The AWS region where the S3 bucket is located. Type: string (required)
Major regions:
  • ap-northeast-2 - Seoul
  • us-east-1 - N. Virginia
  • us-west-2 - Oregon
  • eu-west-1 - Ireland
  • ap-southeast-1 - Singapore

bucket

The S3 bucket name for storing files. Type: string (required)
Using different buckets per environment:

visibility

Sets the ACL (Access Control List) for S3 objects. Type: "public" | "private"
  • "public": Public read allowed (public-read ACL)
  • "private": Private (private ACL, default)

Practical Examples

Development Environment: fs Only

fs + S3 (Environment-based Switching)

Register both drivers, then select which driver to use in code based on an environment variable.
.env.development:
.env.production:
DriverKey currently supports only "fs" and "s3". Multiple bucket configurations — such as separating public and private files into different buckets — are not supported at this time.

File Upload Usage

After storage configuration, you can upload files using the @upload decorator and BufferedFile.saveToDisk().
File Upload Guide

S3 Bucket Setup

Before using S3, you need to create and configure a bucket in AWS Console.

1. Create Bucket

2. CORS Configuration

Configure CORS to allow direct uploads from frontend. S3 Console → Bucket → Permissions → CORS configuration:

3. IAM Permissions

Sonamu needs appropriate IAM permissions to access S3. Minimum permissions policy:

Cautions

1. Environment Variable Security

2. Choosing visibility

3. File Path Design

Next Steps

After completing storage configuration: