Skip to content

Newbie: how do I fetch a doc's blob? #86

@akavel

Description

@akavel

I'm trying to learn iroh and experiment to build an app with it, but I must admit I'm finding the docs extremely confusing and hard to use. The only way I managed to somewhat progress was by, unfortunately, resorting to assistance of chatgpt. But even with that, I've now hit a roadblock that I have no idea how to overcome, at something that feels like it should be a basic thing - I can't find an answer to the question:

How do I fetch the contents of a Blob that was stored as a value in a Doc?

As a "reader" of a Doc, I do have its ticket. Based on it, I tried to do:

        let (doc, _) = docs.import_and_subscribe(ticket.clone()).await.ctx("importing doc ticket")?;
        let entries = doc.get_many(Query::all().build()).await.ctx("querying doc entries")?;
        let mut entries = Box::pin(entries);
        while let Some(entry) = entries.next().await {
            let Ok(entry) = entry else {
                continue;
            };
            let value_hash = entry.content_hash();

Now, apparently, if I just try to do blobs.get_bytes(value_hash), I'm not guaranteed to get the bytes, as they might be not fetched yet. Ok; but how do I fetch the bytes corresponding to the hash?

I currently can find only two ways that look like possibly they might allow me to have the bytes fetched:

  1. blobs.remote().fetch(...) - but this seems to require Connection - and I'm at loss where to get it from;
  2. blobs.downloader().download(...) - this now seems to require some list of EndpointIds - and when I try to pass the endpoint I have available, I seem to get an error from that operation: Unable to download <...my_hash...>.

What do I need to do to be able to fetch the data for the value_hash, which is added in a different instance? I already have blobs, docs, and gossip passed into a router. What am I missing, and how can I get it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    👍 Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions