Initial commit: immich-sdk v1.137.0
This commit is contained in:
59
examples/upload_photos.rs
Normal file
59
examples/upload_photos.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
//! Example: Upload photos to Immich
|
||||
|
||||
use immich_sdk::Client;
|
||||
use std::path::Path;
|
||||
|
||||
#[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");
|
||||
|
||||
// Path to the photo
|
||||
let photo_path = Path::new("/path/to/your/photo.jpg");
|
||||
|
||||
// Upload the photo
|
||||
println!("Uploading: {}", photo_path.display());
|
||||
|
||||
let result = client
|
||||
.assets()
|
||||
.upload()
|
||||
.file(photo_path)
|
||||
.device_asset_id("my-photo-001")
|
||||
.device_id("my-computer")
|
||||
.favorite()
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
match result.status {
|
||||
immich_sdk::models::AssetUploadStatus::Created => {
|
||||
println!("Successfully uploaded! Asset ID: {:?}", result.id);
|
||||
}
|
||||
immich_sdk::models::AssetUploadStatus::Duplicate => {
|
||||
println!("Photo already exists (duplicate)");
|
||||
}
|
||||
_ => {
|
||||
println!("Upload status: {:?}", result.status);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an album and add the uploaded asset
|
||||
if let Some(asset_id) = result.id {
|
||||
let album = client
|
||||
.albums()
|
||||
.create()
|
||||
.name("Uploaded Photos")
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
client
|
||||
.albums()
|
||||
.add_assets(album.id)
|
||||
.asset_ids([asset_id])
|
||||
.execute()
|
||||
.await?;
|
||||
|
||||
println!("Added to album: {}", album.album_name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user