Download an object

Getting data from Lattice using the SDK

This page explains how to download an object from Lattice.

Before you begin

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:

1

Get the object path

When using the DownloadObject API, you must specify the object path of the object you want to download at runtime.

In the previous 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.
2

Download the object

Run the following code from the same folder where you saved the image. To upload, the example calls the UploadObject operation. Replace the following:

  • object_path: the unique path of the object in Lattice.
1package main
2
3import (
4 "context"
5 "fmt"
6 "io"
7 "net/http"
8 "os"
9
10 Lattice "github.com/anduril/lattice-sdk-go/v2"
11 "github.com/anduril/lattice-sdk-go/v2/client"
12 "github.com/anduril/lattice-sdk-go/v2/option"
13)
14
15func main() {
16 // Get environment variables
17 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
18 environmentToken := os.Getenv("ENVIRONMENT_TOKEN")
19
20 // Remove sandboxesToken from the following statements if you are not developing on Sandboxes
21 sandboxesToken := os.Getenv("SANDBOXES_TOKEN")
22
23 // Check required environment variables
24 if latticeEndpoint == "" || environmentToken == "" || sandboxesToken == "" {
25 fmt.Println("Missing required environment variables")
26 os.Exit(1)
27 }
28
29 // Initialize headers for sandbox authorization
30 headers := http.Header{}
31 headers.Add("Anduril-Sandbox-Authorization", fmt.Sprintf("Bearer %s", sandboxesToken))
32
33 // Create the client
34 c := client.NewClient(
35 option.WithToken(environmentToken),
36 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
37 option.WithHTTPHeader(headers),
38 )
39 // Set object path
40 objectPath := "<objectPath>"
41
42 // Create context for the request
43 ctx := context.Background()
44
45 // Get the object
46 request := &Lattice.GetObjectRequest{} // Empty request with default options
47 response, err := c.Objects.GetObject(ctx, objectPath, request)
48 if err != nil {
49 fmt.Printf("Error getting object: %v\n", err)
50 os.Exit(1)
51 }
52 // Create output file
53 file, err := os.Create(objectPath)
54 if err != nil {
55 fmt.Printf("Error creating file: %v\n", err)
56 os.Exit(1)
57 }
58 defer file.Close()
59
60 // Copy data from response to file
61 _, err = io.Copy(file, response)
62 if err != nil {
63 fmt.Printf("Error writing to file: %v\n", err)
64 os.Exit(1)
65 }
66
67 fmt.Printf("Object downloaded successfully. Object path: %s\n", objectPath)
68}
3

Verify the response

If successful, you’ll see the following output:

$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?