Skip to Content
ExamplesFile Attachments

File Attachments

End-to-end FILE column workflow: create a table with a FILE column, upload bytes with multipart SQL, parse the returned metadata, and download the file through the same client.

Source: link/sdks/rust/examples/file-attachments/

Requires the file-uploads feature on kalam-client (included in the example’s Cargo.toml).

What it does

  1. Creates a temporary namespace and documents table with an attachment FILE column
  2. Inserts a row using execute_with_files and FILE("attachment")
  3. Selects the row and parses the FILE cell with as_bound_file(&table_id)
  4. Downloads bytes with download_bound_file
  5. Verifies the payload matches and drops the namespace

Run it

BASH
cd link/sdks/rustexport KALAMDB_SERVER_URL=http://localhost:2900export KALAMDB_ROOT_PASSWORD=kalamdb123cargo run -p file-attachments

Expected output (values vary per run):

TEXT
row id: doc1file name: note.txtstored size: 46 bytesrelative url: /v1/files/rust_file_ex_.../documents/f0001/...-note.txtdownloaded: "Hello from the Rust SDK file-attachments example"content-type: Some("text/plain")

Key APIs

RUST
use kalam_client::{FileUpload, QueryParam, TableId}; let table_id = TableId::from_strings(&namespace, "documents"); let files = vec![    FileUpload::new("attachment", "note.txt", bytes).with_mime("text/plain"),]; client    .execute_with_files(        r#"INSERT INTO docs.documents (id, attachment)           VALUES ($1, FILE("attachment"))"#,        files,        Some(vec![QueryParam::from("doc1")]),        None,    )    .await?; let bound = row[attachment_index]    .as_bound_file(&table_id)    .expect("FILE column"); let download = client.download_bound_file(&bound, None).await?;

Reuse one TableId when parsing many rows from the same table. See FILE Columns & Uploads for the full API reference.

Next

Last updated on