Skip to main content
PocketBase handles file uploads through the file field type. When you create or update a record with file fields, you can upload new files, manage existing ones, and delete unwanted files.

Upload workflow

The file upload process follows these steps:
1

Validate file constraints

PocketBase checks the file against the field’s MaxSize, MaxSelect, and MimeTypes constraints.
2

Normalize filename

The original filename is sanitized and a random 10-character suffix is appended for uniqueness.
3

Upload to storage

The file is uploaded to the storage backend (local or S3) at the path: {collection}/{recordId}/{filename}
4

Save to database

Only the filename is stored in the record field, not the full path.
5

Generate thumbnails

If the file is an image and thumbnails are configured, they’re generated on first request.

Creating File instances

PocketBase provides several methods to create File objects for upload:

From multipart form data

From local file path

From bytes

From URL

Single vs. multiple files

The field’s MaxSelect property determines whether it accepts single or multiple files.

Single file field (MaxSelect ≤ 1)

Multiple files field (MaxSelect > 1)

Advanced file operations

PocketBase provides special setter keys for managing multiple files:

Append files

Add new files to the end of existing files:

Prepend files

Add new files to the beginning:

Remove files

Delete specific files from the field:
When you remove files using the - operator or by replacing the field value, the actual files are deleted from storage after the record is successfully saved.

File validation

PocketBase automatically validates files based on the field configuration:

Size validation

The default maximum file size is 5MB. You can set MaxSize to 0 to use the default, or specify a custom value up to 2^53-1 bytes.

MIME type validation

Count validation

Direct filesystem upload

For advanced use cases, you can upload files directly to the filesystem without using record fields:

Upload raw bytes

Upload multipart file directly

When using direct filesystem uploads, you’re responsible for managing file paths, cleanup, and access control. For most use cases, use the file field type instead.

Error handling

File upload errors are handled during record validation and save:

Complete example

Here’s a complete example of handling file uploads in a custom endpoint:

Next steps

File download

Learn how to serve and download files

S3 storage

Configure cloud storage for files