Skip to the page

Learn · Data & files

Files & object storage

A file is a record that extends ext::files::File. The bytes go straight to object storage, and file links follow the record’s access rules.

In the schema
ext::files::File

File records#

Declare using extension files; and extend ext::files::File on any object type that carries a file, such as user documents, avatars, mobile video uploads or multi-gigabyte ML Parquet shards. The entity in PostgreSQL owns metadata, snapshot visibility and access policies while dedicated cluster buckets hold raw bytes. Every inherited field starts with file_ and carries a safe default, so you can extend ext::files::File on an existing populated table in one migration.

Verified magic bytes
Napalm reads magic bytes from the stored object instead of trusting upload headers.
Direct object storage
Bytes stream straight between clients and object storage.
Policy-bound links
Presigned URLs come only with rows the caller may read.
dbschema/default.gel
using extension auth;using extension files;using extension napalm;using future simple_scoping; module default {  global caller := global ext::auth::ClientTokenIdentity;   type Scan extending ext::files::File {    required owner: ext::auth::Identity;     constraint expression on (std::contains([ext::files::Format.Pdf], .file_format)) {      errmessage := 'a PDF is required';    };     access policy owner_has_full_access      allow all      using (.owner ?= global caller);  }   type Avatar extending ext::files::File {    overloaded required file_is_public: bool {      default := true;    };    required owner: ext::auth::Identity {      constraint exclusive;    };     constraint expression on (std::contains(      [ext::files::Format.Png, ext::files::Format.Jpeg, ext::files::Format.Webp], .file_format)) {      errmessage := 'an image is required';    };     access policy anyone_can_see      allow select;    access policy owner_can_change      allow insert, update, delete      using (.owner ?= global caller);  }}
Inherited fieldTypePurpose
file_nameoptional strPurposeOriginal filename used in the Content-Disposition download header.
file_sizeoptional int64PurposeExpected byte count. Setting file_size on insert or update opens an upload session.
file_statusext::files::StatusPurposeEmpty, Uploading or Ready.
file_formatoptional FormatPurposeSniffed binary format (Pdf, Png, Jpeg, Webp or Mp4) set on completion.
file_erroroptional UploadErrorPurposeReason the last upload failed verification (SizeMismatch, TypeMismatch, NotAccepted, NotUploaded or Expired).
file_is_publicboolPurposeWhether the object lives in the public bucket with a permanent URL (default false).
file_uploadoptional jsonPurposeUpload token and presigned PUT plan, returned only in the mutation that sets file_size.
file_urloptional strPurposeInline viewing URL for Ready files. Presigned for private files and permanent for public files.
file_download_urloptional strPurposeDownload URL that sets Content-Disposition: attachment with file_name.

During completion, Napalm reads the stored object’s magic bytes to determine file_format and evaluates any schema constraints on file_format before marking the record Ready. SVG uploads are classified as Other rather than an image format so user-uploaded SVGs cannot execute inline scripts in a browser tab.

Direct-to-storage upload flow#

Uploading a file takes three steps. First, create or update the record with file_size to obtain a one-time file_upload plan. Next, PUT the bytes directly to object storage (or fetch multipart URLs via POST /uploads/parts for large files). Finally, call POST /uploads/complete to verify the stored bytes and mark the record Ready.

File record

Each ext::files::File record in PostgreSQL enforces insert, select and update policies, mints the one-time file_upload plan and verifies sniffed magic bytes.

Object bucket

Direct-to-bucket uploads stream immutable bytes straight into your cluster’s dedicated object bucket with If-None-Match: * without passing through query engines.

insert.edgeql
select (insert Scan {  owner := global caller,  file_name := <str>$name,  file_size := <int64>$size,}) { id, file_upload }
Schema-authorized
Your insert and update access policies control uploads, because only the insert or update that sets file_size receives file_upload. Later select queries always see null.
Write-once keys
Every upload writes a new object with If-None-Match: *. A file’s bytes are immutable once Ready. Replacing a file creates a new object key so existing references and backups stay intact.
Verified before Ready
If the stored byte count differs from file_size or the sniffed file_format fails a constraint, Napalm deletes the rejected object and records the failure in file_error.

See File uploads for complete single-part and multipart HTTP examples. React Native and Flutter cover resumable uploads from a phone. Web console: S3 imports covers migrating existing files from an external bucket.

Once file_status is Ready, selecting file_url or file_download_url returns a URL alongside your record’s other fields. Callers filtered out by your select access policy never receive the row or the URL.

Policy-gated presigned URLs and window caching

Private file_url and file_download_url links issue only on rows permitted by select policies, reusing one signature per 1-hour window (6-hour TTL) so browser and CDN caches hit cleanly.

links.edgeql
select Scan {  file_name,  file_size,  file_status,  file_url,  file_download_url,}filter .owner ?= global callerorder by .file_name

Private URLs are signed once in each 1-hour window and stay valid for 6 hours. Repeated queries within the same window produce the exact same URL, so browser and CDN caches hit cleanly.

Public files and custom domains#

Setting file_is_public := true when opening an upload places the object in your cluster’s public bucket. A public file’s file_url is unsigned and permanent, so public files suit avatars, marketing images and open datasets. The bucket choice is fixed once the upload completes.

Public files default to an isolated bucket hostname separate from your app domain. You can bind a custom CNAME domain to either bucket from the console or Clusters API. Remove the CNAME record when you stop using the domain, and before a torn-down cluster’s buckets are deleted. A record that points at a deleted bucket lets the next owner of the bucket name serve files on your domain.

Garbage collection and backups#

Deleting a row or replacing a file keeps the stored object until the backup retention window passes. A nightly sweep removes unreferenced objects and expired uploads once no point-in-time restore can reach those bytes.

Backup-pinned retention and storage sweeps

Unreferenced ext::files::File objects stay retained across the active backup window so point-in-time restores resolve every byte, then purge via nightly sweeps or napalm storage sweep.

Stored bytes never change, so point-in-time restores and --data branches always resolve the exact file bytes referenced by every restored row. Compiled Parquet training shards and model checkpoints resolve the same way.

Type a word or two to search every docs page.