SiaSia Developer Portal

Download an Object

Once your app has stored an object, getting it back is straightforward: look it up by its Object ID and download it. The SDK handles all network coordination — it finds the object’s encrypted pieces, fetches them from storage providers, verifies them, and decrypts the data locally.

Downloads return a reader that streams decrypted bytes as they arrive. Copy the reader into any destination — an in-memory buffer, a file, or another writable sink — so you can pull small objects fully into memory or stream large ones straight to disk.

Prerequisites

Before proceeding, ensure you have:

  • An App Key returned from a successful connection to an indexer.
  • An Object ID from an object pinned to your account.

Once ready, you can download the object into memory, into a file, or into another writable destination supported by your SDK.

Example

rust
use sia_storage::{app_id, AppKey, AppMetadata, Builder, DownloadOptions, Hash256}; use std::io::{self, Write}; use std::str::FromStr; const INDEXER_URL: &str = "https://sia.storage"; const APP_META: AppMetadata = AppMetadata { // Replace `app_id` with your real 32-byte App ID (hex-encoded, 64 chars). // Generate this ONCE and keep it stable forever for your app. id: app_id!("0000000000000000000000000000000000000000000000000000000000000000"), name: "My App", description: "Demo application", service_url: "https://example.com", logo_url: None, callback_url: None, }; #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<(), Box<dyn std::error::Error>> { // Create a builder that can reconnect using an existing App Key let builder = Builder::new(INDEXER_URL, APP_META)?; // Ask the user for their App Key print!("Enter your App Key (hex): "); io::stdout().flush()?; let mut app_key_hex = String::new(); io::stdin().read_line(&mut app_key_hex)?; let app_key_hex = app_key_hex.trim(); let mut seed = [0u8; 32]; hex::decode_to_slice(app_key_hex, &mut seed)?; let app_key = AppKey::import(seed); // Reconnect using the App Key let sdk = match builder.connected(&app_key).await? { Some(sdk) => sdk, None => { return Err(io::Error::new( io::ErrorKind::PermissionDenied, "invalid App Key", ) .into()) } }; println!("\nApp Connected!"); // Ask the user for the Object ID to download print!("Enter the Object ID to download: "); io::stdout().flush()?; let mut object_id = String::new(); io::stdin().read_line(&mut object_id)?; let object_id = Hash256::from_str(object_id.trim())?; // Look up the object from the indexer let obj = sdk.object(&object_id).await?; // Download the object into memory let mut reader = sdk.download(&obj, DownloadOptions::default())?; let mut bytes = Vec::new(); tokio::io::copy(&mut reader, &mut bytes).await?; println!("\nObject downloaded!"); println!(" - Contents: {}", String::from_utf8_lossy(&bytes)); Ok(()) }

Understand what happened

The object came back without the indexer or any storage provider ever seeing its contents. Along the way, the SDK:

  • Looked up the object’s slab layout from the indexer using the Object ID.
  • Fetched encrypted shards from storage providers and verified their integrity.
  • Reconstructed and decrypted the data locally, on the device.

Because objects are erasure-coded, the SDK only needs a subset of each slab’s shards to reconstruct the data. It requests more than it needs and uses the first ones to arrive, so slow or unreachable providers don’t block the download.

From here, you can attach application-defined, encrypted metadata with the Object Metadata recipe, share an object with a link, or read how indexers keep your data healthy.