Storage architecture
All file operations in Zipline go through a unified datasource abstraction:src/lib/datasource/Datasource.ts for the full interface.
Available datasources
Zipline currently supports two datasource types:- Local - Stores files on the server’s filesystem
- S3 - Stores files in S3-compatible object storage
Local storage
Configuration
Configure local storage in your environment:How it works
The local datasource:- Stores files in the specified directory
- Uses the filesystem for all operations
- Optimizes uploads by moving temp files instead of copying
- Validates paths to prevent directory traversal attacks
src/lib/datasource/Local.ts.
File operations
Uploading
When a file is uploaded:- Saved to temp directory (configured via
coreTempDirectory) - Validated and processed
- Moved to the datasource directory using
copyFile+rm - Original temp file deleted
src/lib/datasource/Local.ts:41-63.
Reading
Files are read as Node.js streams:Deleting
Files are deleted using Node’srm function:
Path security
The local datasource validates all file paths:../../etc/passwd.
Advantages
- Simple setup
- No external dependencies
- Fast for single-server deployments
- Direct filesystem access
Limitations
- Not suitable for multi-server deployments
- No built-in redundancy
- Backups require filesystem-level tools
- Storage limited to single disk/partition
S3 storage
Configuration
Configure S3-compatible storage:How it works
The S3 datasource:- Uses AWS SDK v3 (
@aws-sdk/client-s3) - Validates access on startup by testing read/write/delete
- Streams uploads from disk to minimize memory usage
- Handles large files with multipart operations
- Supports subdirectories for organizing files within a bucket
src/lib/datasource/S3.ts.
Startup validation
When Zipline starts with S3 storage:src/lib/datasource/S3.ts:81-139.
File operations
Uploading
Files are uploaded usingPutObjectCommand:
src/lib/datasource/S3.ts:167-199.
Reading
Files are retrieved as streams:Range requests
For video streaming and partial content:src/lib/datasource/S3.ts:303-327.
Large file operations
For files larger than 5GB, S3 uses multipart copy:src/lib/datasource/S3.ts:329-416.
Subdirectories
Organize files within a bucket using subdirectories:subdirectory: 'zipline', file abc123.png becomes zipline/abc123.png.
Connection pooling
S3 datasource uses connection pooling for performance:src/lib/datasource/S3.ts:54-65.
Advantages
- Highly scalable
- Built-in redundancy
- Multi-server support
- Automatic backups (depending on provider)
- Geographic distribution
- Pay-per-use pricing
Limitations
- Requires external service
- Network latency for operations
- Egress costs (downloading)
- More complex setup
Switching datasources
To switch from local to S3:- Upload existing files to S3 bucket manually
- Update configuration to use S3 datasource
- Update database if file paths changed
- Restart Zipline
- Verify files are accessible
- Delete old local files after confirming migration
- Download all files from S3 to local directory
- Update configuration to use local datasource
- Restart Zipline
- Verify files are accessible
Storage statistics
Total size
Get total storage usage:ListObjectsCommand and sums ContentLength
Individual file size
stat() to get file size
S3: Uses HeadObjectCommand to get metadata
Temporary directory
All uploads are initially saved to a temporary directory:os.tmpdir() + '/zipline'
The temp directory is used for:
- Initial file reception
- Image compression
- GPS metadata removal
- Chunked upload assembly
Temp files are automatically cleaned up after upload completes or fails.
FAQs
Can I use multiple datasources simultaneously?
Can I use multiple datasources simultaneously?
No, Zipline uses a single datasource for all files. You cannot mix local and S3 storage within the same instance.
What S3-compatible services are supported?
What S3-compatible services are supported?
Any S3-compatible service works: AWS S3, MinIO, Backblaze B2, DigitalOcean Spaces, Wasabi, Cloudflare R2, etc. Use the
endpoint and forcePathStyle options for non-AWS services.How do I backup my files?
How do I backup my files?
For local storage, use filesystem backup tools (rsync, tar, etc.). For S3 storage, use S3 versioning, cross-region replication, or bucket lifecycle policies.
Can I use network-attached storage (NAS) with local datasource?
Can I use network-attached storage (NAS) with local datasource?
Yes, mount your NAS to the server and point
DATASOURCE_LOCAL_DIRECTORY to the mount point. Ensure proper permissions and network reliability.What happens if S3 is unavailable?
What happens if S3 is unavailable?