FILE Columns & Uploads
kalam-client supports multipart SQL uploads and authenticated downloads for KalamDB FILE columns.
Enable uploads with the file-uploads feature (included in native-full):
Upload files with SQL
Use FILE("placeholder") in SQL and pass matching FileUpload payloads:
Use execute_with_files_with_progress(...) when you need upload progress callbacks.
Insert + read FileRefs (end-to-end)
For many rows from the same table, reuse one TableId:
Why table context is separate
FILE column JSON is table-agnostic — it stores id, sub, name, size, mime, sha256, and optional shard. Namespace and table name are not embedded in stored JSON.
Download URLs require table identity:
The SDK binds that context at parse time:
| Type | Role |
|---|---|
FileRef | Wire/storage metadata from the FILE column JSON |
TableId | Type-safe namespace + table pair from kalamdb-commons |
FileRefContext | Wraps a TableId for download context |
BoundFileRef | FileRef + FileRefContext — URLs and downloads need no extra args |
FileRef model
FileRef is re-exported from kalamdb-commons. Parse from query cells:
Build download URLs when you already know namespace and table strings:
Prefer BoundFileRef when table identity is known — see below.
Fields and helpers
id,sub,name,size,mime,sha256, optionalshardstored_name()— sanitized filename used in HTTP pathsrelative_path()— storage layout (sub/id-name.ext, shard-aware for shared tables)format_size(),is_image(),is_pdf(),type_description(), and related MIME helpers
BoundFileRef and TableId
Attach table context when parsing cells:
Construct manually when needed:
Download APIs
| Method | When to use |
|---|---|
download_bound_file(&BoundFileRef, target_user_id) | Preferred — context already bound |
download_file(&FileRef, namespace, table, target_user_id) | Legacy explicit namespace/table strings |
Both return FileDownload:
bytes: Vec<u8>content_type: Option<String>content_disposition: Option<String>
For USER tables, downloads default to the authenticated caller’s scope. Pass Some("user_id") as target_user_id when a DBA or system role needs another user’s file (same rules as the HTTP API’s user_id query parameter).
Auth behavior
Downloads use the same JWT (or basic-auth exchange) as SQL queries. The client builds the request URL, applies auth headers, and returns the response body as bytes.
Related server docs
Example
Runnable source: File Attachments (cargo run -p file-attachments from link/sdks/rust).