Object Store Walkthrough
NOTICE: Experimental Preview

Prerequisite: enabling JetStream

If you are running a local nats-server stop it and restart it with JetStream enabled using nats-server -js (if that's not already done)
You can then check that JetStream is enabled by using
1
nats account info
Copied!
Which should output something like:
1
Connection Information:
2
3
Client ID: 6
4
Client IP: 127.0.0.1
5
RTT: 64.996µs
6
Headers Supported: true
7
Maximum Payload: 1.0 MiB
8
Connected URL: nats://127.0.0.1:4222
9
Connected Address: 127.0.0.1:4222
10
Connected Server ID: ND2XVDA4Q363JOIFKJTPZW3ZKZCANH7NJI4EJMFSSPTRXDBFG4M4C34K
11
12
JetStream Account Information:
13
14
Memory: 0 B of Unlimited
15
Storage: 0 B of Unlimited
16
Streams: 0 of Unlimited
17
Consumers: 0 of Unlimited
Copied!
If you see the below instead then JetStream is not enabled
1
JetStream Account Information:
2
3
JetStream is not supported in this account
Copied!

Creating an Object Store bucket

Just like you need to create streams before you can use them you need to first create an Object Store bucket
1
nats object add myobjbucket
Copied!
which outputs
1
myobjbucket Object Store Status
2
3
Bucket Name: myobjbucket
4
Replicas: 1
5
TTL: unlimitd
6
Sealed: false
7
Size: 0 B
8
Backing Store Kind: JetStream
9
JetStream Stream: OBJ_myobjbucket
Copied!

Putting a file in the bucket

1
nats object put myobjbucket ~/Movies/NATS-logo.mov
Copied!
1
1.5 GiB / 1.5 GiB [====================================================================================]
2
3
Object information for myobjbucket > /Users/jnmoyne/Movies/NATS-logo.mov
4
5
Size: 1.5 GiB
6
Modification Time: 14 Apr 22 00:34 +0000
7
Chunks: 12,656
8
Digest: sha-256 8ee0679dd1462de393d81a3032d71f43d2bc89c0c8a557687cfe2787e926
Copied!

Listing the objects in a bucket

1
nats object ls myobjbucket
Copied!
1
╭───────────────────────────────────────────────────────────────────────────╮
2
│ Bucket Contents │
3
├─────────────────────────────────────┬─────────┬───────────────────────────┤
4
│ Name │ Size │ Time │
5
├─────────────────────────────────────┼─────────┼───────────────────────────┤
6
│ /Users/jnmoyne/Movies/NATS-logo.mov │ 1.5 GiB │ 2022-04-13T17:34:55-07:00 │
7
╰─────────────────────────────────────┴─────────┴───────────────────────────╯
Copied!

Getting an object from the bucket

1
nats object get myobjbucket ~/Movies/NATS-logo.mov
Copied!
1
1.5 GiB / 1.5 GiB [====================================================================================]
2
3
Wrote: 1.5 GiB to /Users/jnmoyne/NATS-logo.mov in 5.68s average 279 MiB/s
Copied!

Removing an object from the bucket

1
nats object rm myobjbucket ~/Movies/NATS-logo.mov
Copied!
1
? Delete 1.5 GiB byte file myobjbucket > /Users/jnmoyne/Movies/NATS-logo.mov? Yes
2
Removed myobjbucket > /Users/jnmoyne/Movies/NATS-logo.mov
3
myobjbucket Object Store Status
4
5
Bucket Name: myobjbucket
6
Replicas: 1
7
TTL: unlimitd
8
Sealed: false
9
Size: 16 MiB
10
Backing Store Kind: JetStream
11
JetStream Stream: OBJ_myobjbucket
Copied!

Getting information about the bucket

1
nats object info myobjbucket
Copied!
1
myobjbucket Object Store Status
2
3
Bucket Name: myobjbucket
4
Replicas: 1
5
TTL: unlimitd
6
Sealed: false
7
Size: 1.6 GiB
8
Backing Store Kind: JetStream
9
JetStream Stream: OBJ_myobjbucket
Copied!

Watching for changes to a bucket

1
nats object watch myobjbucket
Copied!
1
[2022-04-13 17:51:28] PUT myobjbucket > /Users/jnmoyne/Movies/NATS-logo.mov: 1.5 GiB bytes in 12,656 chunks
2
[2022-04-13 17:53:27] DEL myobjbucket > /Users/jnmoyne/Movies/NATS-logo.mov
Copied!

Sealing a bucket

You can seal a bucket, meaning that no further changes are allowed on that bucket
1
nats object seal myobjbucket
Copied!
1
? Really seal Bucket myobjbucket, sealed buckets can not be unsealed or modified Yes
2
myobjbucket has been sealed
3
myobjbucket Object Store Status
4
5
Bucket Name: myobjbucket
6
Replicas: 1
7
TTL: unlimitd
8
Sealed: true
9
Size: 1.6 GiB
10
Backing Store Kind: JetStream
11
JetStream Stream: OBJ_myobjbucket
Copied!

Deleting a bucket

Using nats object rm myobjbucket will delete the bucket and all the files stored in it.