alepha@docs:~/docs/reference/primitives$
cat $bucket.md1 min read
#$bucket
#Import
typescript
1import { $bucket } from "alepha/bucket";
#Overview
Creates a bucket primitive for file storage and management with configurable validation.
Provides a comprehensive file storage system that handles uploads, downloads, validation, and management across multiple storage backends with MIME type and size limit controls.
Key Features
- Multi-provider support (filesystem, cloud storage, in-memory)
- Automatic MIME type and file size validation
- Event integration for file operations monitoring
- Flexible per-bucket and per-operation configuration
- Smart file type and size detection
Common Use Cases
- User profile pictures and document uploads
- Product images and media management
- Document storage and retrieval systems
#Options
| Option | Type | Required | Description |
|---|---|---|---|
provider |
Service<FileStorageProvider> | "memory" |
No | File storage provider configuration for the bucket |
name |
string |
No | Unique name identifier for the bucket |
#Examples
ts
1class MediaService { 2 images = $bucket({ 3 name: "user-images", 4 mimeTypes: ["image/jpeg", "image/png", "image/gif"], 5 maxSize: 5 // 5MB limit 6 }); 7 8 documents = $bucket({ 9 name: "documents",10 mimeTypes: ["application/pdf", "text/plain"],11 maxSize: 50 // 50MB limit12 });13 14 async uploadProfileImage(file: FileLike, userId: string): Promise<string> {15 const fileId = await this.images.upload(file);16 await this.userService.updateProfileImage(userId, fileId);17 return fileId;18 }19 20 async downloadDocument(documentId: string): Promise<FileLike> {21 return await this.documents.download(documentId);22 }23 24 async deleteDocument(documentId: string): Promise<void> {25 await this.documents.delete(documentId);26 }27}