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

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 "github.com/anduril/lattice-sdk-go/v2/client"
10 "github.com/anduril/lattice-sdk-go/v2/option"
11)
12
13func main() {
14 // Get environment variables
15 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
16 environmentToken := os.Getenv("ENVIRONMENT_TOKEN")
17
18 // Remove sandboxesToken from the following statements if you are not developing on Sandboxes
19 sandboxesToken := os.Getenv("SANDBOXES_TOKEN")
20
21 // Check required environment variables
22 if latticeEndpoint == "" || environmentToken == "" || sandboxesToken == "" {
23 fmt.Println("Missing required environment variables")
24 os.Exit(1)
25 }
26
27 // Initialize headers for sandbox authorization
28 headers := make(map[string][]string)
29 headers["Anduril-Sandbox-Authorization"] = []string{fmt.Sprintf("Bearer %s", sandboxesToken)}
30
31 // Create the client
32 c := client.NewClient(
33 option.WithToken(environmentToken),
34 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
35 option.WithHTTPHeader(headers),
36 )
37 // Set object path
38 objectPath := "<objectPath>"
39
40 // Create context for the request
41 ctx := context.Background()
42
43 // Get the object metadata using HEAD request
44 response, err := c.Objects.WithRawResponse.GetObjectMetadata(ctx, objectPath)
45 if err != nil {
46 fmt.Printf("Error getting object metadata: %v\n", err)
47 os.Exit(1)
48 }
49
50 // The response contains headers with metadata information
51 fmt.Println("Object Metadata:")
52 fmt.Printf("Status Code: %d\n", response.StatusCode)
53 fmt.Printf("Path: %s\n", response.Header.Get("Path"))
54 fmt.Printf("Content-Length: %s bytes\n", response.Header.Get("Content-Length"))
55 fmt.Printf("Checksum: %s\n", response.Header.Get("Checksum"))
56 fmt.Printf("Last-Modified: %s\n", response.Header.Get("Last-Modified"))
57 fmt.Printf("Expires: %s\n", response.Header.Get("Expires"))
58 fmt.Println("Object metadata retrieved successfully")
59}
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 "context"
5 "fmt"
6 "net/http"
7 "os"
8 "path/filepath"
9 "strconv"
10
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
40 // File path of the object to upload
41 filePath := "path/to/file.jpg"
42
43 // Set TTL to 1 hour in nanoseconds
44 ttlInNanoseconds := int64(1 * 60 * 60 * 1000000000) // 1 hour in nanoseconds
45
46 // Create context for the request
47 ctx := context.Background()
48
49 // Open the file
50 file, err := os.Open(filePath)
51 if err != nil {
52 fmt.Printf("Error opening file: %v\n", err)
53 os.Exit(1)
54 }
55 defer file.Close()
56
57 // Get file name for object path
58 objectPath := filepath.Base(filePath)
59
60 // Create TTL header
61 ttlHeaders := http.Header{}
62 ttlHeaders.Add("Time-To-Live", strconv.FormatInt(ttlInNanoseconds, 10))
63
64 // Upload object with TTL header
65 response, err := c.Objects.UploadObject(
66 ctx,
67 objectPath,
68 file,
69 option.WithHTTPHeader(ttlHeaders),
70 )
71 if err != nil {
72 fmt.Printf("Error uploading object: %v\n", err)
73 os.Exit(1)
74 }
75
76 fmt.Printf("Object uploaded successfully. Object path: %s\n", response.ContentIdentifier.Path)
77 fmt.Printf("Object will expire after %d seconds\n", ttlInNanoseconds/1000000000)
78
79 // Verify the expiry time by getting object metadata
80 metadataResponse, err := c.Objects.WithRawResponse.GetObjectMetadata(ctx, objectPath)
81 if err != nil {
82 fmt.Printf("Error getting object metadata: %v\n", err)
83 os.Exit(1)
84 }
85
86 fmt.Printf("Expiry time confirmed: %s\n", metadataResponse.Header.Get("Expires"))
87}
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 delete_object
3
4import (
5 "context"
6 "fmt"
7 "os"
8
9 "github.com/anduril/lattice-sdk-go/v2/client"
10 "github.com/anduril/lattice-sdk-go/v2/option"
11)
12
13func DeleteObject() {
14 // Get environment variables
15 latticeEndpoint := os.Getenv("LATTICE_ENDPOINT")
16 environmentToken := os.Getenv("ENVIRONMENT_TOKEN")
17
18 // Remove sandboxesToken from the following statements if you are not developing on Sandboxes
19 sandboxesToken := os.Getenv("SANDBOXES_TOKEN")
20
21 // Check required environment variables
22 if latticeEndpoint == "" || environmentToken == "" || sandboxesToken == "" {
23 fmt.Println("Missing required environment variables")
24 os.Exit(1)
25 }
26
27 // Initialize headers for sandbox authorization
28 headers := make(map[string][]string)
29 headers["Anduril-Sandbox-Authorization"] = []string{fmt.Sprintf("Bearer %s", sandboxesToken)}
30
31 // Create the client
32 c := client.NewClient(
33 option.WithToken(environmentToken),
34 option.WithBaseURL(fmt.Sprintf("https://%s", latticeEndpoint)),
35 option.WithHTTPHeader(headers),
36 )
37 // Set object path to delete
38 objectPath := "<objectPath>"
39
40 // Create context for the request
41 ctx := context.Background()
42
43 // Delete the object
44 err := c.Objects.DeleteObject(ctx, objectPath)
45 if err != nil {
46 fmt.Printf("Error deleting object: %v\n", err)
47 os.Exit(1)
48 }
49
50 fmt.Printf("Object deleted successfully: %s\n", objectPath)
51
52 // Try to access the object to verify it's deleted
53 _, err = c.Objects.WithRawResponse.GetObjectMetadata(ctx, objectPath)
54 if err != nil {
55 fmt.Println("Verification successful: Object no longer exists.")
56 fmt.Printf("Expected error: %v\n", err)
57 } else {
58 fmt.Println("Warning: Object still exists after deletion attempt.")
59 }
60}

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.