Skip to main content
Learn how to save files to local, S3, GCS, and other storage using Sonamu’s Storage Manager.

Storage Manager Overview

Unified Interface

Single API Multiple storage support

Driver System

local, s3, gcs Extensible

saveToDisk()

Easy saving Auto URL generation

Disk Management

Multiple disk configuration Purpose-based separation

Basic Usage

The saveToDisk() method of UploadedFile is the simplest way to save files.

Disk Selection

Using Storage Manager Directly

Basic Usage

You can use Storage Manager directly when saveToDisk() cannot be used.

Using Specific Disk

Storage Configuration

storage.config.ts

Storage Driver API

put() - Save File

Parameters:
  • key: string - Storage path
  • data: Uint8Array - File data
  • options: { contentType?: string } - Options

get() - Read File

delete() - Delete File

exists() - Check File Existence

getUrl() - Generate Public URL

getSignedUrl() - Generate Signed URL

Practical Examples

Date-based Folder Structure

User-based Folder Structure

Category-based Disk Selection

Image Optimization Before Saving

Save to Multiple Disks Simultaneously

File Deletion

Delete File

Check Existence Before Deletion

Advanced Usage

Streaming Upload (Large Files)

For large files, use @upload({ consume: "stream" }). Files are streamed directly to the specified storage destination. Access the already-uploaded file info via context.uploadedFiles.

Saving File Metadata

Cautions

Cautions when saving files: 1. saveToDisk() is the simplest method 2. Verify disk configuration 3. Set file size limits 4. Error handling is essential 5. Consider streaming for large files

Next Steps

File Upload Setup

@upload decorator

UploadedFile Class

File info access

URL Generation

Generating URLs

@api Decorator

API basic usage