Skip to main content
PocketBase provides a built-in API endpoint for serving files from records. The system handles content type detection, range requests, caching, and security headers automatically.

Download endpoint

Files are served through the following endpoint:

Path parameters

  • collection - The collection name or ID
  • recordId - The record ID
  • filename - 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:
This sets 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 content
  • Content-Disposition - inline for viewable files, attachment for downloads
  • Cache-Control - Valid for 30 days with background revalidation
  • Content-Security-Policy - Restrictive CSP for security
  • ETag - For cache validation
  • Last-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 has Protected: true, users must provide a valid file token to access files.

Getting a file token

Authenticated users can request a file token:
Response:

Using the file token

Append the token to file URLs:
File tokens are time-limited. Protected files also respect collection view rules - even with a valid token, users can only access files from records they have permission to view.

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/png
  • image/jpg / image/jpeg
  • image/gif
  • image/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:
Response:
Range requests are handled automatically by http.ServeContent, enabling video streaming and resumable downloads.

Inline content types

These content types are served with Content-Disposition: inline by default:
All other types are served as 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