> For the complete documentation index, see [llms.txt](https://bittu-1.gitbook.io/meshkit-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bittu-1.gitbook.io/meshkit-documentation/api/download.md).

# download()

## Overview

Downloads file content from IPFS by CID using the configured gateway.

## Purpose

Use `download()` to fetch binary content previously uploaded with `upload()` or otherwise available by CID.

## Endpoint / Method

```ts
async download(cid: string): Promise<Blob>
```

Gateway request:

```http
GET {gatewayUrl}/{cid}
```

## Parameters

| Name  | Type     | Required | Description                         |
| ----- | -------- | -------- | ----------------------------------- |
| `cid` | `string` | Yes      | Raw CID or URL containing `/ipfs/`. |

### Request schema table

| Field | Type     | Required | Notes                                                                                                           |
| ----- | -------- | -------- | --------------------------------------------------------------------------------------------------------------- |
| `cid` | `string` | Yes      | Normalized by trimming, extracting the `/ipfs/` segment, removing query strings, and removing trailing slashes. |

## Response

Returns `Promise<Blob>`.

| Value  | Description                           |
| ------ | ------------------------------------- |
| `Blob` | File content returned by the gateway. |

### Response schema table

| Type   | Description                                              |
| ------ | -------------------------------------------------------- |
| `Blob` | Result of `response.blob()` from the configured gateway. |

## Examples

### Example request

```ts
const blob = await meshkit.download("bafybeifileexamplecid");
const text = await blob.text();
```

### Example response

```ts
// Blob
console.log(blob.size);
console.log(blob.type);
```

## Errors

| Error                                          | Cause                                          |
| ---------------------------------------------- | ---------------------------------------------- |
| `Invalid CID`                                  | CID is empty after trimming and normalization. |
| `Failed to fetch from gateway. HTTP error 404` | Gateway could not resolve the CID.             |
| Network error                                  | Runtime could not reach the gateway.           |

### Error schema table

| Field     | Type     | Description                                                  |
| --------- | -------- | ------------------------------------------------------------ |
| `name`    | `string` | Standard JavaScript error name.                              |
| `message` | `string` | `Invalid CID`, gateway HTTP error, or network error message. |

## Notes

* Use `retrieve()` for JSON content that should be parsed automatically.
* The returned `Blob.type` depends on gateway response headers.

## Best Practices

* Convert the `Blob` only after checking expected size and content type where possible.
* Use object URLs carefully and revoke them when no longer needed in browser contexts.
* Store original filenames separately if your app needs to restore them.

## Related APIs

* [upload()](/meshkit-documentation/api/upload.md)
* [retrieve()](/meshkit-documentation/api/retrieve.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bittu-1.gitbook.io/meshkit-documentation/api/download.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
