Skip to the page

Reference · Project API

File uploads

Stream file bytes directly to object storage and let Napalm verify size and format rules before marking the record ready.

CLI
—
In the schema
ext::files::File

Three-step upload lifecycle#

File uploads separate metadata authorization in PostgreSQL from direct byte transfer to object storage, then verify size and header magic bytes before marking the record Ready.

Direct-to-bucket upload and byte check

Setting file_size returns a one-time file_upload descriptor. POST /uploads/complete sniffs leading bytes and enforces file_format constraints.

Policy-gated presigned download URLs

Selecting file_url or file_download_url mints short-lived signed links only for files the caller’s select rules permit.

  1. Create or update the record with file_size

    Request · curl
    curl https://notes.napalmdata.com/query \  -H "Authorization: Bearer $SESSION" \  -H "Content-Type: application/json" \  -d {    "query": "select (insert Scan { owner := global caller, file_name := <str>$name, file_size := <int64>$size }) { id, file_upload }",    "variables": { "name": "lease.pdf", "size": 2431604 }  }
    Response
    {  "data": [{    "id": "0192c3f4-6b1a-7d8e-9f00-1a2b3c4d5e6f",    "file_upload": {      "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…",      "expires": "2026-10-19T08:26:09Z",      "method": "PUT",      "url": "https://…/files/8939870e-3d20-4fdd-9f0a-471487890dbe?X-Amz-Signature=…",      "headers": { "Content-Length": "2431604", "If-None-Match": "*" }    }  }]}

    Only the mutation that sets file_size receives a non-null file_upload descriptor. Later select queries return null for file_upload. A single-part descriptor holds a presigned PUT url and the required headers. A multipart descriptor for a large file holds part_size and part_count instead of a single url, and POST /uploads/parts returns the presigned part URLs.

  2. Stream the bytes directly to object storage

    Browser or client upload
    await fetch(file_upload.url, { method: file_upload.method, headers: file_upload.headers, body: file })
  3. Finalize and verify the upload

    POST/uploads/complete#

    Request · curl
    curl https://notes.napalmdata.com/uploads/complete \  -H "Authorization: Bearer $SESSION" \  -H "Content-Type: application/json" \  -d '{ "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…" }'
    Response
    {  "token": "up_Y4_FLCcYYXRfsAgv1nz3jN2…",  "key": "8939870e-3d20-4fdd-9f0a-471487890dbe",  "is_public": false,  "size": 2431604,  "format": "Pdf",  "content_type": "application/pdf"}

    POST /uploads/complete checks that the stored object matches the declared file_size, sniffs the magic bytes from the file header to set file_format, evaluates any schema constraints on file_format and transitions file_status to Ready. Repeat calls with the same token are idempotent.

Napalm’s clients do steps 2 and 3 in one call with napalm.upload(file_upload, file). The call handles multipart parts too.

See Files & object storage for schema definitions, presigned download links (file_url and file_download_url) and public buckets.

Upload verification and multipart routes#

RouteJSON request bodyBehavior
POST /uploads/complete{ "token": "up_…" }BehaviorVerifies stored byte length and magic-byte format, enforces schema constraints and marks the file Ready.
POST /uploads/parts#{ "token", "first"?, "count"? }BehaviorReturns presigned PUT URLs for a batch of multipart upload parts (up to 1,000 parts per call).

Both routes require a valid read-write bearer credential (Authorization: Bearer <token>) in addition to the upload token.

Verification error codes#

Error codefile_error enumCause
not_uploadedNotUploadedCauseNo object was uploaded to the presigned URL before /uploads/complete was called.
size_mismatchSizeMismatchCauseThe uploaded byte count does not match the file_size declared on the record.
not_acceptedNotAcceptedCauseThe detected file_format violates a schema constraint on the object type (for example, uploading a PDF to an image-only type).
type_mismatchTypeMismatchCauseThe uploaded bytes do not match the declared content type on a public file.
parts_incomplete—CauseOne or more multipart parts did not arrive whole. Nothing is recorded or deleted. Send the missing parts and call /uploads/complete again.
expired_uploadExpiredCauseThe upload token expired before /uploads/complete was called.

When verification fails, Napalm deletes the rejected bytes from object storage and records the reason in the record’s file_error property. The upload token stays open until expiry so the client can retry. If an upload expires unverified, file_status resets to Empty, and your application can open a new upload by setting file_size again.

Type a word or two to search every docs page.