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.
Create or update the record with file_size
Request · curlcurl 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_sizereceives a non-nullfile_uploaddescriptor. Laterselectqueries returnnullforfile_upload. A single-part descriptor holds a presignedPUTurland the requiredheaders. A multipart descriptor for a large file holdspart_sizeandpart_countinstead of a singleurl, andPOST /uploads/partsreturns the presigned part URLs.Stream the bytes directly to object storage
Browser or client uploadawait fetch(file_upload.url, { method: file_upload.method, headers: file_upload.headers, body: file })Finalize and verify the upload
POST/uploads/complete#
Request · curlcurl 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/completechecks that the stored object matches the declaredfile_size, sniffs the magic bytes from the file header to setfile_format, evaluates any schema constraints onfile_formatand transitionsfile_statustoReady. 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#
| Route | JSON request body | Behavior |
|---|---|---|
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 code | file_error enum | Cause |
|---|---|---|
not_uploaded | NotUploaded | CauseNo object was uploaded to the presigned URL before /uploads/complete was called. |
size_mismatch | SizeMismatch | CauseThe uploaded byte count does not match the file_size declared on the record. |
not_accepted | NotAccepted | CauseThe detected file_format violates a schema constraint on the object type (for example, uploading a PDF to an image-only type). |
type_mismatch | TypeMismatch | CauseThe 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_upload | Expired | CauseThe 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.