Skip to main content
PocketBase provides built-in file management capabilities with support for local and S3-compatible storage, automatic file validation, and thumbnail generation for images.

File fields

File storage is handled through file fields in your collections:

File field options

MaxSelect

Controls whether the field stores a single file or multiple files:

MaxSize

Specifies the maximum file size in bytes:
If not set, the default maximum size is 5MB per file.

MimeTypes

Restricts allowed file types:
Leave empty to allow all file types.

Thumbs

Defines thumbnail sizes for image files:
Thumbnails are generated automatically for supported image formats.

Protected

Controls file access:
Even public files have randomized filenames (e.g., document_Ab3Kf9g2.pdf), providing obscurity. Protected files require a short-lived token for access.

Uploading files

Single file upload

Multiple file upload

Modifying uploaded files

File modifiers

File fields support special modifier operations:

File storage

Storage structure

Files are stored in the following hierarchy:

Filename normalization

PocketBase automatically adds a random suffix to filenames:
This prevents:
  • Filename conflicts
  • Guessing file URLs
  • Accidental overwrites

Accessing files

File URLs

Public file URLs

For non-protected files:
Example:

Protected file URLs

For protected files, generate a file token:

Thumbnail URLs

Access image thumbnails:
Example:

File validation

Automatic validation

File fields automatically validate:
  • File count (MaxSelect)
  • File size (MaxSize)
  • MIME type (MimeTypes)
  • Filename format

Custom validation

File operations

Listing files

Finding files

Deleting files

Files are automatically deleted when:
  1. Record is deleted
  2. File field value is updated (old files removed)
  3. File is explicitly removed using modifiers

S3 storage

PocketBase supports S3-compatible storage (AWS S3, MinIO, DigitalOcean Spaces, etc.):
When switching from local to S3 storage, you must manually migrate existing files. New files will automatically use S3.

File hooks

Upload processing

Post-upload actions

File deletion

Direct filesystem access

Getting filesystem instance

File operations

List files

Performance optimization

Set reasonable MaxSize limits. Smaller files upload faster and consume less storage. Consider compressing large files client-side before upload.
Only generate thumbnails you actually use. Each thumbnail size requires storage space and processing time.
Use a CDN in front of your PocketBase instance to cache and serve files closer to users.
Load images on-demand rather than all at once. Use smaller thumbnails for previews and full-size images only when needed.
S3-compatible storage is generally more reliable and scalable than local filesystem storage for production deployments.
Regularly check for and remove orphaned files or old temporary files to save storage space.

Security best practices

Don’t rely solely on MIME types - they can be spoofed. Verify file contents match expected types.
PocketBase automatically sanitizes filenames, but be cautious when using user-provided filenames in other contexts.
Implement virus scanning for uploaded files, especially for user-facing applications.
Set Protected: true for files containing sensitive information. This requires authentication to access.
Limit file upload frequency and size per user to prevent abuse and resource exhaustion.
Configure CORS properly if files need to be accessed from different domains.