Upload files
Files are uploaded as part of record create/update operations usingmultipart/form-data.
Create record with file
multipart/form-data to upload files with record data.
Update record files
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)
protected: true)
Response
Returns the file with appropriateContent-Type header.
Generate file token
Generate a token to access protected files.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 is100x100, 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:- File token (recommended for client-side access)
- Direct auth (collection’s
viewRuleis checked)
File field options
When defining file fields in collections, you can configure:File URLs
File URLs follow this pattern:View collection files
For view collections, files are served from the original collection record:Best practices
- Use appropriate MIME type restrictions for security
- Set reasonable
maxSizelimits - 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