Manage objects

Getting metadata, and managing the lifecycle of objects using the Lattice SDK

In Lattice, an object is a data model that represents a single file or a piece of data. This page explains how to manage objects in Lattice, including retrieving metadata, setting expiration times, and deleting objects.

Before you begin

gRPC authentication

If you are using gRPC with client credentials, set up the token refresh module before running the examples on this page.

Get object metadata

To retrieve metadata about an object without downloading its contents, use the getObjectMetadata method, which performs a HEAD request to the server.

This operation returns metadata such as the object size in bytes, the SHA-256 checksum, and timestamps indicating when the object was last modified, and when it expires.

1

Specify the object path

When using the GetObjectMetadata API, you must specify the object path of the object for which you want to retrieve metadata.

For example, if you previously uploaded an image at /api/v1/objects/image.jpg, you would use this path to request its metadata.

2

Get the object metadata

Run the following code to retrieve the object’s metadata. Replace objectPath with the path of the object.

1// Example code for getting object metadata
2package main
3
4import (
5 "context"
6 "fmt"
7 "os"
8
9 Lattice "github.com/anduril/lattice-sdk-go/v4"
10 "github.com/anduril/lattice-sdk-go/v4/client"
11 "github.com/anduril/lattice-sdk-go/v4/option"
12)
13
14func main() {
15 // Get environment variables
16 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
17 clientSecret := os.Getenv("LATTICE_CLIENT_SECRET")
18 clientId := os.Getenv("LATTICE_CLIENT_ID")
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 == "" || clientId == "" || clientSecret == "" || sandboxesToken == "" {
25 fmt.Println("Missing required environment variables")
26 os.Exit(1)
27 }
28
29 // Initialize headers for sandbox authorization
30 headers := make(map[string][]string)
31 headers["Anduril-Sandbox-Authorization"] = []string{fmt.Sprintf("Bearer %s", sandboxesToken)}
32
33 // Create the client
34 c := client.NewClient(
35 option.WithClientCredentials(clientId, clientSecret),
36 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
37 option.WithHTTPHeader(headers),
38 )
39 // Set object path
40 objectPath := "<OBJECT_PATH>"
41
42 // Create context for the request
43 ctx := context.Background()
44
45 // Get the object metadata using HEAD request
46 response, err := c.Objects.WithRawResponse.GetObjectMetadata(ctx, &Lattice.GetObjectMetadataRequest{ObjectPath: objectPath})
47 if err != nil {
48 fmt.Printf("Error getting object metadata: %v\n", err)
49 os.Exit(1)
50 }
51
52 // The response contains headers with metadata information
53 fmt.Println("Object Metadata:")
54 fmt.Printf("Status Code: %d\n", response.StatusCode)
55 fmt.Printf("Path: %s\n", response.Header.Get("Path"))
56 fmt.Printf("Content-Length: %s bytes\n", response.Header.Get("Content-Length"))
57 fmt.Printf("Checksum: %s\n", response.Header.Get("Checksum"))
58 fmt.Printf("Last-Modified: %s\n", response.Header.Get("Last-Modified"))
59 fmt.Printf("Expires: %s\n", response.Header.Get("Expires"))
60 fmt.Println("Object metadata retrieved successfully")
61}
3

Inspect the metadata

If successful, the response will include headers with valuable information:

$Object metadata:
$- Path: your_object_path.jpg
$- Content-Length: 2000000 bytes
$- Checksum: 4191337226643912nbab1784de94c4f58bb78bf98bfb9916474b2fe5decbbaa6
$- Last-Modified: Thu, 30 Oct 2025 00:30:41 UTC
$- Expires: Thu, 30 Oct 2025 01:30:41 UTC

You can use this information to verify the object size before downloading, confirm the object hasn’t been modified using the checksum, and check when the object expires and is removed from your environment.

Set object time-to-live

In Lattice, an object is a data model that represents a single file or a piece of data. When uploading objects, you can control how long they will be stored in Lattice by setting a Time-To-Live (TTL) value. This is useful for temporary files or for implementing storage policies.

1

Prepare the file and TTL value

Before uploading, you need to:

  1. Have a file ready to upload
  2. Determine the desired time-to-live in nanoseconds

For example, to keep an object for 24 hours, you would set the TTL to: 24 * 60 * 60 * 1,000,000,000 nanoseconds (86,400,000,000,000 ns)

2

Upload with TTL header

Use the Lattice SDK to upload the object, adding the Time-To-Live request header to specify the TTL:

1package main
2
3import (
4 "bytes"
5 "context"
6 "fmt"
7 "net/http"
8 "os"
9 "path/filepath"
10 "strconv"
11
12 Lattice "github.com/anduril/lattice-sdk-go/v4"
13 "github.com/anduril/lattice-sdk-go/v4/client"
14 "github.com/anduril/lattice-sdk-go/v4/option"
15)
16
17func main() {
18 // Get environment variables
19 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
20 clientSecret := os.Getenv("LATTICE_CLIENT_SECRET")
21 clientId := os.Getenv("LATTICE_CLIENT_ID")
22
23 // Remove sandboxesToken from the following statements if you are not developing on Sandboxes
24 sandboxesToken := os.Getenv("SANDBOXES_TOKEN")
25
26 // Check required environment variables
27 if latticeEndpoint == "" || clientId == "" || clientSecret == "" || sandboxesToken == "" {
28 fmt.Println("Missing required environment variables")
29 os.Exit(1)
30 }
31
32 // Initialize headers for sandbox authorization
33 headers := http.Header{}
34 headers.Add("Anduril-Sandbox-Authorization", fmt.Sprintf("Bearer %s", sandboxesToken))
35
36 // Create the client
37 c := client.NewClient(
38 option.WithClientCredentials(clientId, clientSecret),
39 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
40 option.WithHTTPHeader(headers),
41 )
42
43 // File path of the object to upload
44 filePath := "<FILE_PATH_TTL>"
45
46 // Set TTL to 1 hour in nanoseconds
47 ttlInNanoseconds := int64(1 * 60 * 60 * 1000000000) // 1 hour in nanoseconds
48
49 // Create context for the request
50 ctx := context.Background()
51
52 // Read the file contents into a byte slice.
53 fileContent, err := os.ReadFile(filePath)
54 if err != nil {
55 fmt.Printf("Error reading file: %v\n", err)
56 os.Exit(1)
57 }
58
59 // Get file name for object path
60 objectPath := filepath.Base(filePath)
61
62 // Create TTL header
63 ttlHeaders := http.Header{}
64 ttlHeaders.Add("Time-To-Live", strconv.FormatInt(ttlInNanoseconds, 10))
65
66 // Upload object with TTL header
67 response, err := c.Objects.UploadObject(
68 ctx,
69 objectPath,
70 bytes.NewReader(fileContent),
71 option.WithHTTPHeader(ttlHeaders),
72 )
73 if err != nil {
74 fmt.Printf("Error uploading object: %v\n", err)
75 os.Exit(1)
76 }
77
78 fmt.Printf("Object uploaded successfully. Object path: %s\n", response.ContentIdentifier.Path)
79 fmt.Printf("Object will expire after %d seconds\n", ttlInNanoseconds/1000000000)
80
81 // Verify the expiry time by getting object metadata
82 metadataResponse, err := c.Objects.WithRawResponse.GetObjectMetadata(ctx, &Lattice.GetObjectMetadataRequest{ObjectPath: objectPath})
83 if err != nil {
84 fmt.Printf("Error getting object metadata: %v\n", err)
85 os.Exit(1)
86 }
87
88 fmt.Printf("Expiry time confirmed: %s\n", metadataResponse.Header.Get("Expires"))
89}
3

Verify the expiry time

If successful, Lattice sets an expiry time based on the value you specify in the Time-To-Live header. The example from the previous steps confirms the result by fetching the object’s metadata and checking the Expires header:

$Object expires on Mon, 01 Jan 2026 00:00:00 UTC

If you don’t set a TTL, Lattice will use a default typically set to 90 days. This default TTL policy might vary, based on your environment’s configurations.

Delete an object

In Lattice, an object is a data model that represents a single file or a piece of data. When you no longer need an object, you can delete it from Lattice to free up storage space. Deleting an object is a permanent operation that cannot be undone.

1

Delete the object

When using the DeleteObject API, you must specify the object path of the object you want to delete.

Replace the object path with your information, then run the following code to delete the object:

1// Example code for deleting an object
2package main
3
4import (
5 "context"
6 "fmt"
7 "os"
8
9 Lattice "github.com/anduril/lattice-sdk-go/v4"
10 "github.com/anduril/lattice-sdk-go/v4/client"
11 "github.com/anduril/lattice-sdk-go/v4/option"
12)
13
14func main() {
15 // Get environment variables
16 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
17 clientSecret := os.Getenv("LATTICE_CLIENT_SECRET")
18 clientId := os.Getenv("LATTICE_CLIENT_ID")
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 == "" || clientId == "" || clientSecret == "" || sandboxesToken == "" {
25 fmt.Println("Missing required environment variables")
26 os.Exit(1)
27 }
28
29 // Initialize headers for sandbox authorization
30 headers := make(map[string][]string)
31 headers["Anduril-Sandbox-Authorization"] = []string{fmt.Sprintf("Bearer %s", sandboxesToken)}
32
33 // Create the client
34 c := client.NewClient(
35 option.WithClientCredentials(clientId, clientSecret),
36 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
37 option.WithHTTPHeader(headers),
38 )
39 // Set object path to delete
40 objectPath := "<DELETE_OBJECT_PATH>"
41
42 // Create context for the request
43 ctx := context.Background()
44
45 // Delete the object
46 err := c.Objects.DeleteObject(ctx, &Lattice.DeleteObjectRequest{ObjectPath: objectPath})
47 if err != nil {
48 fmt.Printf("Error deleting object: %v\n", err)
49 os.Exit(1)
50 }
51
52 fmt.Printf("Object deleted successfully: %s\n", objectPath)
53
54 // Try to access the object to verify it's deleted
55 _, err = c.Objects.WithRawResponse.GetObjectMetadata(ctx, &Lattice.GetObjectMetadataRequest{ObjectPath: objectPath})
56 if err != nil {
57 fmt.Println("Verification successful: Object no longer exists.")
58 fmt.Printf("Expected error: %v\n", err)
59 } else {
60 fmt.Println("Warning: Object still exists after deletion attempt.")
61 }
62}

If successful, this produces an error with the following output: the object no longer exists”

$Object deleted successfully: test.jpg
$Status: 404

What’s next?

  • Learn more about the Objects API.
  • Explore how to use objects with Entities to associate binary data with your Lattice entities.