Overview
TheFileStore 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
Recommended: Factory Method
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
- Use the factory method for immediate validation of storage access
- Set appropriate limits based on your application needs
- Monitor storage usage to prevent running out of space
- Use metadata to organize and search files
- Handle errors gracefully - files can fail validation
- Clean up old files periodically to manage storage
- Back up the file directory - FileStore doesn’t handle backups