Skip to main content

upload_and_feed/
upload_and_feed.rs

1//! Upload a file and publish it under a feed — a stable handle that always
2//! serves the latest version. Needs a stamped Bee node.
3//!
4//!   BEE_NODE=http://localhost:1633 BEE_STAMP=<batch> \
5//!     cargo run --example upload_and_feed -- <file>
6
7use scout::LiteClient;
8
9#[tokio::main]
10async fn main() -> anyhow::Result<()> {
11    let file = std::env::args().nth(1).expect("usage: upload_and_feed <file>");
12    let node = std::env::var("BEE_NODE").unwrap_or_else(|_| "http://localhost:1633".into());
13    let stamp = std::env::var("BEE_STAMP").expect("set BEE_STAMP to a usable postage batch id");
14
15    // Reads use the node here too; in practice the read endpoint can be a gateway.
16    let scout = LiteClient::read(&node)?.with_write(&node, &stamp)?;
17
18    let data = std::fs::read(&file)?;
19    let file_ref = scout.up_bytes(data).await?;
20    println!("uploaded:      {file_ref}");
21
22    // A throwaway feed identity for the demo; persist this key to keep the handle.
23    let (key, _owner, _pubkey) = scout::generate_key()?;
24    let handle = scout.publish(&key, "example-feed", &file_ref).await?;
25    println!("feed handle:   {handle}");
26    println!("read latest:   scout cat {handle} --gateway {node}");
27    Ok(())
28}