Storage Overview

File storage abstraction for local filesystem and S3-compatible storage.

The @kit/storage package provides a unified storage abstraction layer built on unstorage. It offers a consistent API for file operations across different storage providers.

The checked-in runtime currently wires two providers: local filesystem storage for development and S3-compatible storage for production-style setups.

Features

  • Upload files with metadata (content type, cache control)
  • Download files as Buffer
  • Delete files and prefixes
  • List files by prefix
  • Generate public URLs
  • Support for filesystem and S3-compatible providers

Supported Providers

The kit supports the following providers:

  • Filesystem - Local development (default)
  • S3 - AWS S3, or S3-compatible storage (R2, Blackblaze, etc.)

Unstorage supports a wide range of providers, you can find the complete list here.

Quick Start

Get Storage Instance

import 'server-only';
import { getStorageService } from '@kit/storage';
const storage = await getStorageService();

Upload a File

Upload through the storage service directly:

import { getStorageService } from '@kit/storage';
const storage = await getStorageService();
await storage.setItemRaw('uploads/image.png', buffer);

Download a File

To download a file, you can use the downloadFile helper function.

import { getStorageService } from '@kit/storage';
const storage = await getStorageService();
const data = await storage.getItemRaw('uploads/image.png');

Delete Files

To delete a file, you can use the deleteFile helper function.

import { getStorageService } from '@kit/storage';
const storage = await getStorageService();
// Delete single file
await storage.removeItem('uploads/image.png');

Topics

  1. Configuration - Environment variables and provider setup
  2. Usage - Upload, download, delete operations
  3. Providers - Set up filesystem or S3-compatible storage
  4. Bucket Access - Access control for storage buckets
  5. API Reference - Types and function signatures

Important Notes

  • Server-only - Storage operations must run on the server
  • Provider selection - Set STORAGE_PROVIDER environment variable
  • Development default - Uses local filesystem (./public/storage.dev)
  • Production - Configure a cloud provider

This storage system is part of the Next.js Drizzle SaaS Kit.


Next: Configuration