Skip to main content

Overview

The FileStore class provides secure file storage with automatic validation, MIME type detection, and configurable limits. It’s designed to handle attachments and files in conversational AI applications.

Creating a FileStore

The factory method validates storage access immediately, ensuring the directory is writable.

Direct Constructor

Configuration Options

string
default:"./narrator_files"
Base directory for file storage
int
default:"52428800"
Maximum file size in bytes (default: 50MB)
int
default:"5368709120"
Maximum total storage in bytes (default: 5GB)
Set[str]
default:"common types"
Set of allowed MIME types. Default includes documents, images, archives, and audio formats.

Default Allowed File Types

Saving Files

Retrieving Files

Deleting Files

Storage Management

Error handling

FileStore includes specific exceptions for different error cases:

Integration with Attachments

FileStore is designed to work with the Attachment class:

File Organization

Files are organized by date for easy management:

Example: Document Management System

Best practices

  1. Use the factory method for immediate validation of storage access
  2. Set appropriate limits based on your application needs
  3. Monitor storage usage to prevent running out of space
  4. Use metadata to organize and search files
  5. Handle errors gracefully - files can fail validation
  6. Clean up old files periodically to manage storage
  7. Back up the file directory - FileStore doesn’t handle backups