Skip to main content

Overview

TrailBase includes integrated object storage for managing files like images, documents, and user uploads. Use S3-compatible storage (AWS S3, MinIO, R2, etc.) or local filesystem storage.

Storage Backends

Local Filesystem

Store files directly on the server’s filesystem

Amazon S3

Use AWS S3 buckets for scalable storage

MinIO

Self-hosted S3-compatible storage

Cloudflare R2

S3-compatible with zero egress fees

Local Filesystem Storage

By default, TrailBase stores files in the uploads/ directory:
No configuration needed - it works out of the box:

S3-Compatible Storage

AWS S3

Configure AWS S3 in config.textproto:
Or specify credentials explicitly:

MinIO (Self-Hosted)

MinIO endpoints using http:// are automatically configured to allow HTTP (non-HTTPS) connections.

Cloudflare R2

DigitalOcean Spaces

Configuration Details

From crates/core/src/app_state.rs:

File Management

Upload Files

Files are automatically managed when using file columns in your schema:

File Metadata

TrailBase stores file metadata in a special _files table:

File Deletion

Deleted files are queued for cleanup:
The file deletion job runs hourly to remove orphaned files:

API Integration

Upload via Records API

Download Files

File URLs

Files are served through the records API:

Direct Object Store Access

Access the object store programmatically:

File Processing

Image Resizing

Process uploaded images:

Virus Scanning

Backup and Migration

Backup to S3

Migrate Between Storage

Performance Optimization

CDN Integration

Serve files through a CDN:
Generate CDN URLs:

Caching

Set appropriate cache headers:

Multipart Uploads

For large files, use multipart uploads:

Security

Access Control

Control file access in your schema:

Signed URLs

Generate temporary signed URLs for S3:

Monitoring

Storage Usage

Audit Logging

Best Practices

1

Use S3 for production

Local filesystem is fine for development, but use S3-compatible storage for production scalability and durability.
2

Set lifecycle policies

Configure automatic deletion of old files:
3

Validate file types

Check MIME types and file extensions before storing.
4

Implement virus scanning

Scan uploaded files for malware before serving them.
5

Use CDN

Serve static files through a CDN for better performance.
6

Monitor storage costs

Track usage and set up alerts for unexpected growth.

Next Steps

Custom Endpoints

Build file upload APIs

Jobs Scheduler

Process files in background

OAuth Providers

Store user avatars

Server-Side Rendering

Display file galleries