72 lines
1.9 KiB
Rust
72 lines
1.9 KiB
Rust
//! Example: Download asset thumbnails
|
|
|
|
use immich_sdk::Client;
|
|
use immich_sdk::models::AssetMediaSize;
|
|
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 thumbnail for
|
|
let asset_id = "your-asset-id-here".parse()?;
|
|
|
|
// Download thumbnail (small size, default)
|
|
println!("Downloading thumbnail...");
|
|
let response = client
|
|
.assets()
|
|
.thumbnail(asset_id)
|
|
.size(AssetMediaSize::Thumbnail)
|
|
.execute()
|
|
.await?;
|
|
|
|
println!("Content type: {}", response.content_type());
|
|
println!("Extension: {:?}", response.extension());
|
|
|
|
let ext = response.extension().unwrap_or("jpg");
|
|
let output_path = format!("/path/to/output/thumbnail.{}", ext);
|
|
fs::write(&output_path, response.data())?;
|
|
println!(
|
|
"Saved thumbnail: {} bytes to {}",
|
|
response.data().len(),
|
|
output_path
|
|
);
|
|
|
|
// Download preview (medium size)
|
|
let response = client
|
|
.assets()
|
|
.thumbnail(asset_id)
|
|
.size(AssetMediaSize::Preview)
|
|
.execute()
|
|
.await?;
|
|
|
|
let ext = response.extension().unwrap_or("jpg");
|
|
let output_path = format!("/path/to/output/preview.{}", ext);
|
|
fs::write(&output_path, response.data())?;
|
|
println!(
|
|
"Saved preview: {} bytes to {}",
|
|
response.data().len(),
|
|
output_path
|
|
);
|
|
|
|
// Download fullsize
|
|
let response = client
|
|
.assets()
|
|
.thumbnail(asset_id)
|
|
.size(AssetMediaSize::Fullsize)
|
|
.execute()
|
|
.await?;
|
|
|
|
let ext = response.extension().unwrap_or("jpg");
|
|
let output_path = format!("/path/to/output/fullsize.{}", ext);
|
|
fs::write(&output_path, response.data())?;
|
|
println!(
|
|
"Saved fullsize: {} bytes to {}",
|
|
response.data().len(),
|
|
output_path
|
|
);
|
|
|
|
Ok(())
|
|
}
|