Skip to main content
The Files API allows you to upload files as part of record operations and download files with optional thumbnail generation.

Upload files

Files are uploaded as part of record create/update operations using multipart/form-data.

Create record with file

Use multipart/form-data to upload files with record data.

Update record files

Replace files:
Append files (using + modifier):
Prepend files (using + prefix):
Remove specific files (using - modifier):

Download files

Download files from file field records.
string
required
The collection name or ID
string
required
The record ID containing the file
string
required
The name of the file to download
string
Thumbnail size (e.g., 100x100, 300x200). Only works for images.
string
File token for accessing protected files (see Generate file token)
Authentication: Required for protected files (when field has protected: true)

Response

Returns the file with appropriate Content-Type header.

Generate file token

Generate a token to access protected files.
Authentication: Required (must be authenticated)

Response

string
File access token (valid for the authenticated user’s session)

Thumbnail generation

PocketBase automatically generates thumbnails for image files on-demand.

Supported formats

Thumbnails are generated for:
  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • GIF (.gif)
  • WebP (.webp)

Default sizes

The default thumbnail size is 100x100, but you can configure custom sizes in the collection’s file field settings.

Thumbnail sizes

Specify thumbnail dimensions using {width}x{height} format:
Thumbnails are generated on first request and cached. The original file is served if thumbnail generation fails.

Custom thumbnail sizes

Define custom thumbnail sizes in your collection’s file field configuration:

Protected files

Mark file fields as protected to require authentication for access.

Field configuration

Accessing protected files

Protected files require either:
  1. File token (recommended for client-side access)
  2. Direct auth (collection’s viewRule is checked)

File field options

When defining file fields in collections, you can configure:

File URLs

File URLs follow this pattern:
You can construct file URLs from record data:

View collection files

For view collections, files are served from the original collection record:
PocketBase automatically resolves the file to the original collection’s record.

Best practices

  • Use appropriate MIME type restrictions for security
  • Set reasonable maxSize limits
  • Use protected files for sensitive documents
  • Generate thumbnails only for sizes you need
  • Consider CDN caching for public files

File naming

PocketBase automatically handles file naming:
  • Generates unique filenames to prevent collisions
  • Preserves file extensions
  • Sanitizes filenames for safe storage

Storage

Files are stored in:
Thumbnails are stored in:

Common errors