Download endpoint
Files are served through the following endpoint:Path parameters
collection- The collection name or IDrecordId- The record IDfilename- The exact filename stored in the record
Example request
Query parameters
You can modify the download behavior using query parameters:Thumbnail request
Request a specific thumbnail size for image files:Thumbnails are generated on-demand on the first request and cached for subsequent requests. They’re stored at
{collection}/{recordId}/thumbs_{filename}/{thumbSize}_{filename}.Force download
Force the browser to download the file instead of displaying it inline:Content-Disposition: attachment instead of inline.
Protected file access
For protected files, include the file token:Response headers
PocketBase sets appropriate headers for file serving:Header details
Content-Type- Automatically detected from file contentContent-Disposition-inlinefor viewable files,attachmentfor downloadsCache-Control- Valid for 30 days with background revalidationContent-Security-Policy- Restrictive CSP for securityETag- For cache validationLast-Modified- File modification timestamp
The
X-Frame-Options header is removed for file endpoints to allow embedding files in iframes.Protected files
When a file field hasProtected: true, users must provide a valid file token to access files.
Getting a file token
Authenticated users can request a file token:Using the file token
Append the token to file URLs:Implementation details
The download endpoint implementation (from apis/file.go:84):Thumbnail generation
Thumbnails are generated using the filesystem.CreateThumb method (from filesystem.go:489):Supported image formats
Thumbnail generation works with:image/pngimage/jpg/image/jpegimage/gifimage/webp
WebP images are decoded for thumbnail generation, but the thumbnails are saved as PNG to ensure broad compatibility.
Serving files programmatically
You can serve files in custom endpoints using the filesystem:Getting file reader
For more control, get a file reader:Checking file existence
Getting file attributes
Range requests
PocketBase supports HTTP range requests for partial file downloads:Range requests are handled automatically by
http.ServeContent, enabling video streaming and resumable downloads.Inline content types
These content types are served withContent-Disposition: inline by default:
attachment (download) by default.
Error handling
The download endpoint returns appropriate error responses:Complete example
Here’s a complete example with protected file download:Next steps
File upload
Learn how to upload files to records
S3 storage
Configure cloud storage for scalability