Store and retrieve multi-gigabyte files using NATS JetStream object store with custom chunk size and metadata

domain: docs.nats.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create an object store bucket: js.CreateObjectStore(jetstream.ObjectStoreConfig{Bucket: "artifacts", Storage: jetstream.FileStorage, MaxChunkSize: 512*1024}) — override the 128 KB default chunk size to 512 KB for fewer round-trips on large files
  2. Upload a file: obs.PutFile(ctx, "/local/path/large-file.bin") or use obs.Put(ctx, jetstream.ObjectMeta{Name: "large-file.bin", Description: "build artifact"}, reader) for streaming upload
  3. Retrieve with streaming: obs.GetFile(ctx, "large-file.bin", "/destination/path") or obs.Get(ctx, "large-file.bin") to get an io.ReadCloser and process chunks incrementally
  4. Attach custom metadata: set jetstream.ObjectMeta.Headers to pass arbitrary key-value pairs alongside the object; retrieve via ObjectInfo.Headers after Get
  5. List stored objects: obs.List(ctx) returns a channel of ObjectInfo entries with name, size, and checksum (SHA-256) for integrity verification
  6. Delete an object: obs.Delete(ctx, "large-file.bin") removes all chunks and the metadata subject; the bucket stream is compacted automatically

Known gotchas

Related routes

Configure a NATS JetStream stream with WorkQueue retention for single-consumption FIFO job distribution
docs.nats.io · 6 steps · unrated
Create NATS JetStream streams and push/pull consumers
docs.nats.io · 5 steps · unrated
Use NATS JetStream stream mirroring and sourcing for cross-account replication
nats · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans