storage_fs library

A filesystem abstraction library for Dart, inspired by Laravel's Storage facade.

This library provides a unified API for working with different storage backends including local filesystem and cloud storage (S3-compatible services like AWS S3, Cloudflare R2, MinIO, and others).

Features

  • Multiple storage drivers: Local filesystem, S3-compatible cloud storage
  • Unified API: Same interface for all storage backends
  • Typed disk configurations: Type-safe initialization via Disk subclasses
  • Signed URLs: Generate temporary URLs for cloud storage
  • Configurable: Easy configuration with multiple disk support

Getting Started

First, initialize the storage system with typed disk configurations:

import 'package:storage_fs/storage_fs.dart';

void main() {
  Storage.initialize(
    defaultDisk: 'local',
    disks: [
      LocalDisk(name: 'local', root: '/path/to/storage'),
    ],
  );
}

Basic Usage

Once initialized, use the Storage facade to interact with files:

// Write a file
await Storage.put('hello.txt', 'Hello, World!');

// Read a file
final content = await Storage.get('hello.txt');

// Check if a file exists
if (await Storage.exists('hello.txt')) {
  print('File exists!');
}

// Delete a file
await Storage.delete('hello.txt');

Working with Different Disks

You can work with specific storage disks:

// Use the default disk
await Storage.put('file.txt', 'content');

// Use a specific disk
await Storage.disk('s3').put('file.txt', 'content');

// Use the cloud disk
await Storage.cloud().put('file.txt', 'content');

Cloud Storage Features

Generate temporary signed URLs for secure file access:

final url = await Storage.getTemporaryUrl(
  'private-file.pdf',
  DateTime.now().add(Duration(hours: 1)),
);
print('Download URL (valid for 1 hour): $url');

Directory Operations

// List files in a directory
final files = await Storage.files('documents');

// List all files recursively
final allFiles = await Storage.allFiles('documents');

// Create a directory
await Storage.makeDirectory('uploads');

// Delete a directory
await Storage.deleteDirectory('uploads');

See also:

  • Storage - The main facade for interacting with storage
  • Filesystem - The filesystem contract interface
  • Cloud - The cloud storage contract interface

Classes

Cloud
Contract for cloud filesystem operations.
CloudAdapter
Cloud storage adapter that implements the Cloud contract.
Disk
Typed configuration for a storage disk.
DiskConfig
Configuration for a filesystem disk.
Factory
Contract for filesystem manager factory.
Filesystem
Base contract for filesystem operations.
FilesystemAdapter
Base filesystem adapter providing common functionality using the file package.
FilesystemManager
Manages filesystem instances and drivers.
LocalDisk
Typed configuration for a local filesystem disk.
S3Disk
Typed configuration for an S3-compatible cloud storage disk.
Storage
Provides a static interface for filesystem operations across multiple storage backends.
StorageConfig
Main configuration for the Storage system.

Exceptions / Errors

FilesystemException
Base exception for filesystem operations.
UnableToCopyFileException
Exception thrown when unable to copy a file.
UnableToCreateDirectoryException
Exception thrown when unable to create a directory.
UnableToDeleteDirectoryException
Exception thrown when unable to delete a directory.
UnableToDeleteFileException
Exception thrown when unable to delete a file.
UnableToMoveFileException
Exception thrown when unable to move a file.
UnableToProvideChecksumException
Exception thrown when unable to provide checksum.
UnableToReadFileException
Exception thrown when unable to read a file.
UnableToRetrieveMetadataException
Exception thrown when unable to retrieve metadata.
UnableToSetVisibilityException
Exception thrown when unable to set visibility.
UnableToWriteFileException
Exception thrown when unable to write a file.