Files
fil/docs/snippets/rust/api/client_chunk_text.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

927 B

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let bytes = tokio::fs::read("document.pdf").await?;

    let part = reqwest::multipart::Part::bytes(bytes)
        .file_name("document.pdf")
        .mime_str("application/pdf")?;
    let form = reqwest::multipart::Form::new()
        .part("file", part)
        .text("chunking", r#"{"max_characters":800,"overlap":100}"#);

    let response = client
        .post("http://localhost:8000/extract")
        .multipart(form)
        .send()
        .await?;

    let result: serde_json::Value = response.error_for_status()?.json().await?;
    if let Some(chunks) = result["chunks"].as_array() {
        println!("{} chunks", chunks.len());
        for chunk in chunks {
            println!("  {} chars", chunk["content"].as_str().unwrap_or("").len());
        }
    }
    Ok(())
}