File Download

To Download the file, you need to provide the unique hash of the data(Fid), which will be returned to you when the data is uploaded successfully.

here is the sample code to retrieve the data:

```rust
use cess_rust_sdk::{chain::{ChainSdk, file::File}, config::get_deoss_url};

// The account mnemonic that will be used to sign transactions.
const MNEMONIC: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice";

#[tokio::main]
async fn main() {
    let sdk = ChainSdk::new(MNEMONIC, "service_name");
    // root hash obtained when uploading the file
    let root_hash = "34ec2b81d469aa7cb20b3682e20c317db2b5b8ad604390198ca421c28601abf6";

    // if file name is not specified, the root_hash will be used as the file_name
    let path = "/tmp/test.txt";
    let result = sdk.download_from_gateway(&get_deoss_url(), root_hash, path).await;
    match result {
        Ok(r) => {
            println!("File download successful: {:?}", r);
        }
        Err(e) => {
            println!("File download failed: {:?}", e);
        }
    }
}
```

Last updated