//! Example: Download an asset from Immich //! //! This example uses environment variables for configuration: //! - IMMICH_URL: The Immich server URL (defaults to http://localhost:2283) //! - IMMICH_API_KEY: Your API key (required) use immich_sdk::Client; use std::fs; #[tokio::main] async fn main() -> Result<(), Box> { // Configure the client from environment variables let url = std::env::var("IMMICH_URL").unwrap_or_else(|_| "http://localhost:2283".to_string()); let api_key = std::env::var("IMMICH_API_KEY").expect("IMMICH_API_KEY environment variable not set"); // Create a client let client = Client::from_url(&url)?.with_api_key(api_key); // Get first asset from the server let assets = client.assets().list().execute().await?; if assets.is_empty() { println!("No assets found. Run upload_photos example first."); return Ok(()); } let asset_id = assets[0].id; // 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(()) }