> This is the Markdown version of the page. For the complete Lattice Developers documentation index, fetch https://developer.anduril.com/llms.txt. Append .md to any page URL for its clean Markdown. # Download an object > Getting data from Lattice using the SDK In Lattice, an **object** is a data model that represents a single file or a piece of data. This page explains how to retrieve objects from Lattice. ## Before you begin * To configure your app to upload objects, [set up](/guides/getting-started/set-up) your Lattice environment. * See an overview of the [Object schema and the Object Store API](/guides/objects/overview) in Lattice. ## Download an object In Lattice, an **object** is a data model that represents a single file or a piece of data. To download a specific binary object from Lattice using its unique object path, do the following: #### Get the object path When using the [DownloadObject](/reference/rest/objects/get-object) API, you must specify the object path of the object you want to download at runtime. In the [previous](/guides/objects/upload) procedure, you uploaded the following objects: * Image: A `.jpg` image at the following path: `/api/v1/objects/cessna.jpg`. This image is a thumbnail of its associated track entity. * CSV: A `.csv` file at the following path: `/api/v1/objects/manifest.csv`. This serves as metadata, in this case, a vessel manifest for the associated entity. Choose one, and note the object path. #### Download the object Run the following code in the directory where you'd like to download the object. To download, use the [`GetObject`](/reference/rest/objects/get-object) operation. Replace the following: * **object\_path**: the unique path of the object in Lattice. ```go title={"Go"} maxLines={25} package main import ( "context" "fmt" "io" "net/http" "os" Lattice "github.com/anduril/lattice-sdk-go/v5" "github.com/anduril/lattice-sdk-go/v5/client" "github.com/anduril/lattice-sdk-go/v5/option" ) func main() { // Get environment variables latticeEndpoint := os.Getenv("LATTICE_ENDPOINT") environmentToken := os.Getenv("ENVIRONMENT_TOKEN") // Remove sandboxesToken from the following statements if you are not developing on Sandboxes sandboxesToken := os.Getenv("SANDBOXES_TOKEN") // Check required environment variables if latticeEndpoint == "" || environmentToken == "" || sandboxesToken == "" { fmt.Println("Missing required environment variables") os.Exit(1) } // Initialize headers for sandbox authorization headers := http.Header{} headers.Add("Anduril-Sandbox-Authorization", fmt.Sprintf("Bearer %s", sandboxesToken)) // Create the client c := client.NewClient( option.WithToken(environmentToken), option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)), option.WithHTTPHeader(headers), ) // Set object path objectPath := "" // Create context for the request ctx := context.Background() // Get the object response, err := c.Objects.GetObject(ctx, &Lattice.GetObjectRequest{ObjectPath: objectPath}) if err != nil { fmt.Printf("Error getting object: %v\n", err) os.Exit(1) } // Create output file file, err := os.Create(objectPath) if err != nil { fmt.Printf("Error creating file: %v\n", err) os.Exit(1) } defer file.Close() // Copy data from response to file _, err = io.Copy(file, response) if err != nil { fmt.Printf("Error writing to file: %v\n", err) os.Exit(1) } fmt.Printf("Object downloaded successfully. Object path: %s\n", objectPath) } ``` ```java title={"Java"} maxLines={25} package org.example; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import com.anduril.Lattice; public class Download { public static void main(String[] args) { // Get environment variables String endpoint = System.getenv("LATTICE_ENDPOINT"); String environmentToken = System.getenv("ENVIRONMENT_TOKEN"); String sandboxesToken = System.getenv("SANDBOXES_TOKEN"); // Check required variables and ensure URL has https:// if (endpoint == null || environmentToken == null || sandboxesToken == null) { System.err.println("Missing required environment variables"); System.exit(1); } if (!endpoint.startsWith("https://")) endpoint = "https://" + endpoint; try { // Create Lattice client with Sandbox authentication Lattice client = Lattice.builder() .url(endpoint) .token(environmentToken) .addHeader("Anduril-Sandbox-Authorization", "Bearer " + sandboxesToken) .build(); // Set the file path for downloaded file String objectPath = ""; // Create local file path with the original name and extension. String localFilePath = objectPath; File file = new File(localFilePath); try { // Download the object from Lattice InputStream response = client.objects().getObject(objectPath); // Save the downloaded object to file try (FileOutputStream outputStream = new FileOutputStream(file)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = response.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } System.out.println("Successfully downloaded " + objectPath + " to " + localFilePath); } } catch (Exception e) { System.err.println("Error downloading object: " + e.getMessage()); } } catch (Exception e) { System.err.println("Error initializing client: " + e.getMessage()); } } } ``` ```py title={"Python"} maxLines={25} from anduril import Lattice import os import sys import asyncio lattice_endpoint = os.getenv('LATTICE_ENDPOINT') environment_token = os.getenv('ENVIRONMENT_TOKEN') # Remove sandboxes_token from the following statements if you are not developing on Sandboxes. sandboxes_token = os.getenv('SANDBOXES_TOKEN') if not environment_token or not lattice_endpoint or not sandboxes_token: print("Missing required environment variables.") sys.exit(1) client = Lattice( base_url=f"https://{lattice_endpoint}", token=lambda: str(environment_token), # Remove the following if you are not developing on a Sandboxes. headers={ "anduril-sandbox-authorization": f"Bearer {sandboxes_token}" } ) async def app(object_path): try: response = client.objects.get_object( object_path=object_path ) chunks = [chunk for chunk in response] result = b''.join(chunks) print(f"Downloaded file: {result}") except asyncio.CancelledError: print(">>>Exiting...") except Exception as error: print(f"Exception: {error}") if __name__ == "__main__": # Set the object path to the function to download the object. asyncio.run(app(object_path="")) ``` ```ts title={"Typescript"} maxLines={25} import { LatticeClient } from "@anduril-industries/lattice-sdk"; import { writeFileSync } from 'fs'; const latticeEndpoint = process.env.LATTICE_ENDPOINT; const environmentToken = process.env.ENVIRONMENT_TOKEN; // Remove sandboxesToken from the following statements if you are not developing on Sandboxes. const sandboxesToken = process.env.SANDBOXES_TOKEN; if (!latticeEndpoint || !environmentToken || !sandboxesToken) { console.log('Missing required environment variables.'); process.exit(1); } const client = new LatticeClient( { baseUrl: `https://${latticeEndpoint}`, token: environmentToken, // Remove the header if you are not developing on Sandboxes. headers: { "Anduril-Sandbox-Authorization": `Bearer ${sandboxesToken}` } } ); async function App(objectPath: string) { try { const response = await client.objects.getObject({ objectPath }); const data = new Uint8Array(await response.arrayBuffer()); writeFileSync(objectPath, data); console.log(`Object downloaded successfully. Object path: ${objectPath}`); } catch (error) { if (error instanceof Error && error.name === 'AbortError') { console.log('Process interrupted. Exiting...'); process.exit(0); } else { console.log(`Encountered the following error: ${error}`); process.exit(1); } } } // Replace objectPath with the path of the object you want to download from Lattice. const objectPath = ""; App(objectPath); ``` ```rs title={"Rust"} startLine={35} maxLines={25} use anduril_lattice_sdk::prelude::*; use std::env; #[tokio::main] async fn main() -> Result<(), Box> { let lattice_endpoint = env::var("LATTICE_ENDPOINT") .expect("LATTICE_ENDPOINT environment variable not set"); let environment_token = env::var("ENVIRONMENT_TOKEN") .expect("ENVIRONMENT_TOKEN environment variable not set"); // Remove sandboxes_token if you are not developing on Sandboxes. let sandboxes_token = env::var("SANDBOXES_TOKEN") .expect("SANDBOXES_TOKEN environment variable not set"); if environment_token.is_empty() || lattice_endpoint.is_empty() || sandboxes_token.is_empty() { eprintln!("Missing required environment variables:"); eprintln!(" LATTICE_ENDPOINT"); eprintln!(" ENVIRONMENT_TOKEN"); eprintln!(" SANDBOXES_TOKEN"); std::process::exit(1); } let config = ClientConfig { base_url: format!("https://{}", lattice_endpoint), token: Some(environment_token), // Remove custom_headers if you are not developing on Sandboxes. custom_headers: HashMap::from([( "anduril-sandbox-authorization".to_string(), format!("Bearer {}", sandboxes_token), )]), ..Default::default() }; let client = Lattice::new(config)?; // Set the object path to download. let object_path = ""; match client.objects.get_object(object_path, None).await { // get_object returns a streaming ByteStream. `collect` buffers the whole // object into a Vec; for large files, prefer `try_next` to process // chunks incrementally. Ok(stream) => match stream.collect().await { Ok(bytes) => println!("Downloaded file: {:?}", bytes), Err(e) => eprintln!("Exception: {}", e), }, Err(e) => eprintln!("Exception: {}", e), } Ok(()) } ``` #### Verify the response If successful, you'll see the following output: ```bash INFO - HTTP Request: GET https://lattice-50802.env.sandboxes.developer.anduril.com/api/v1/objects/your_object_name "HTTP/1.1 200 OK" ``` ## What's next? * Learn more about the [Objects API](/reference/rest/objects/list-objects). > Getting data from Lattice using the SDK