Add asset download functionality with builder pattern and example

This commit is contained in:
Joakim Hulthe
2026-04-06 08:04:39 +00:00
parent d04b8b221b
commit 1e38963ff6
2 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
//! Example: Download an asset from Immich
use immich_sdk::Client;
use std::fs;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let client = Client::from_url("https://immich.example.com")?.with_api_key("your-api-key");
// Asset ID to download (replace with a real asset ID)
let asset_id = "your-asset-id-here".parse()?;
// Download the asset
println!("Downloading asset...");
let bytes = client.assets().download(asset_id).execute().await?;
// Save to file
let output_path = "/path/to/output/photo.jpg";
fs::write(output_path, &bytes)?;
println!("Saved {} bytes to {}", bytes.len(), output_path);
// Or download the edited version if available
let edited_bytes = client
.assets()
.download(asset_id)
.edited()
.execute()
.await?;
let edited_path = "/path/to/output/photo_edited.jpg";
fs::write(edited_path, &edited_bytes)?;
println!(
"Saved edited version {} bytes to {}",
edited_bytes.len(),
edited_path
);
Ok(())
}