Configuration options
Maximum size of a single uploaded file in bytes (up to 2^53-1). Defaults to 5MB if not set or zero.
Maximum number of files allowed. Set to 1 (or less) for single file mode. Set to > 1 for multiple files mode.
Optional list of allowed file MIME types. Leave empty to allow all file types.
Optional list of image thumbnail sizes to generate. Each entry must be in a specific format (see Thumbnail formats section).
When true, requires users to provide a special file token to access the file. By default, all files are publicly accessible.
When true, requires at least one file to be uploaded.
Thumbnail formats
For image files, you can specify thumbnails in these formats:WxH(e.g.,100x300) - Crop to WxH viewbox from centerWxHt(e.g.,100x300t) - Crop to WxH viewbox from topWxHb(e.g.,100x300b) - Crop to WxH viewbox from bottomWxHf(e.g.,100x300f) - Fit inside WxH viewbox without cropping0xH(e.g.,0x300) - Resize to H height preserving aspect ratioWx0(e.g.,100x0) - Resize to W width preserving aspect ratio
Validation rules
The file field validates:- File count: Number of files cannot exceed
maxSelect - File size: Each file must be under
maxSizebytes - MIME type: If
mimeTypesis set, files must match one of the allowed types - Filename: Must be 1-150 characters and contain valid characters
- Required: If enabled, at least one file must be uploaded
Special setter modifiers
The file field supports modifiers for manipulating files:Go examples
- Single file upload
- Multiple files
- Protected images
- Any file type
Database column type
The column type varies based on single or multiple files:File URLs
To access uploaded files, construct URLs using the following pattern:Common MIME types
Special getter
The file field provides a special getter to access unsaved files:File naming
Uploaded files automatically get a random suffix appended to their names to ensure uniqueness and prevent collisions. For example,
document.pdf becomes document_x7k2m9p4.pdf.Best practices
- Set appropriate
maxSizelimits based on your use case and storage capacity - Use
mimeTypesto restrict file types and improve security - Generate thumbnails for image galleries to improve performance
- Use
protected: truefor sensitive files that require authentication - Consider the total storage size when setting
maxSelectandmaxSize - Clean up old files when records are deleted (handled automatically by PocketBase)
- The maximum body size for requests is calculated from
maxSize * maxSelect
Zero value
- Single file: Empty string
"" - Multiple files: Empty array
[]